From 9a90e7c57af6fc29202c2af1307905571760f6c9 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Thu, 7 Nov 2013 12:56:01 +0800 Subject: [PATCH] MDL-42754 Messages: Show noreply user notifications With fake noreply and support users, the notifications were not accessible by user Support for viewing messages from noreply user has been added. Signed-off-by: Rajesh Taneja --- lib/classes/user.php | 1 + message/index.php | 10 +++++----- message/lib.php | 25 ++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/classes/user.php b/lib/classes/user.php index badf8540047..7bcee3415af 100644 --- a/lib/classes/user.php +++ b/lib/classes/user.php @@ -128,6 +128,7 @@ class core_user { if (empty(self::$noreplyuser)) { self::$noreplyuser = self::get_dummy_user_record(); + self::$noreplyuser->maildisplay = '1'; // Show to all. } self::$noreplyuser->emailstop = 1; // Force msg stop for this user. return self::$noreplyuser; diff --git a/message/index.php b/message/index.php index e13c486324b..d4c6d4d0752 100644 --- a/message/index.php +++ b/message/index.php @@ -136,7 +136,7 @@ if (substr($viewing, 0, 7) == MESSAGE_VIEW_COURSE) { if (!empty($user1->id) && $user1->id != $USER->id) { $PAGE->navigation->extend_for_user($user1); } -if (!empty($user2->id) && $user2->id != $USER->id) { +if (!empty($user2->id) && $user2realuser && ($user2->id != $USER->id)) { $PAGE->navigation->extend_for_user($user2); } @@ -161,7 +161,7 @@ if ($unblockcontact and confirm_sesskey()) { //was a message sent? Do NOT allow someone looking at someone else's messages to send them. $messageerror = null; -if ($currentuser && $user2realuser && has_capability('moodle/site:sendmessage', $systemcontext)) { +if ($currentuser && !empty($user2) && has_capability('moodle/site:sendmessage', $systemcontext)) { // Check that the user is not blocking us!! if ($contact = $DB->get_record('message_contacts', array('userid' => $user2->id, 'contactid' => $user1->id))) { if ($contact->blocked and !has_capability('moodle/site:readallmessages', $systemcontext)) { @@ -221,7 +221,7 @@ $countunreadtotal = 0; //count of unread messages from all users //we're dealing with unread messages early so the contact list will accurately reflect what is read/unread $viewingnewmessages = false; -if ($user2realuser) { +if (!empty($user2)) { //are there any unread messages from $user2 $countunread = message_count_unread_messages($user1, $user2); if ($countunread>0) { @@ -249,7 +249,7 @@ list($onlinecontacts, $offlinecontacts, $strangers) = message_get_contacts($user message_print_contact_selector($countunreadtotal, $viewing, $user1, $user2, $blockedusers, $onlinecontacts, $offlinecontacts, $strangers, $showactionlinks, $page); echo html_writer::start_tag('div', array('class' => 'messagearea mdl-align')); - if ($user2realuser) { + if (!empty($user2)) { echo html_writer::start_tag('div', array('class' => 'mdl-left messagehistory')); @@ -306,7 +306,7 @@ echo html_writer::start_tag('div', array('class' => 'messagearea mdl-align')); echo html_writer::end_tag('div'); //send message form - if ($currentuser && has_capability('moodle/site:sendmessage', $systemcontext)) { + if ($currentuser && has_capability('moodle/site:sendmessage', $systemcontext) && $user2realuser) { echo html_writer::start_tag('div', array('class' => 'mdl-align messagesend')); if (!empty($messageerror)) { echo html_writer::tag('span', $messageerror, array('id' => 'messagewarning')); diff --git a/message/lib.php b/message/lib.php index bf9f73fd07e..74333c67d73 100644 --- a/message/lib.php +++ b/message/lib.php @@ -378,6 +378,17 @@ function message_get_contacts($user1=null, $user2=null) { } $rs->close(); + // Add noreply user and support user to the list. + $supportuser = core_user::get_support_user(); + $supportuser->messagecount = message_count_unread_messages($USER, $supportuser); + if ($supportuser->messagecount > 0) { + $strangers[] = $supportuser; + } + $noreplyuser = core_user::get_noreply_user(); + $noreplyuser->messagecount = message_count_unread_messages($USER, $noreplyuser); + if ($supportuser->messagecount > 0) { + $strangers[] = $noreplyuser; + } return array($onlinecontacts, $offlinecontacts, $strangers); } @@ -1941,7 +1952,12 @@ function message_print_message_history($user1, $user2 ,$search = '', $messagelim echo html_writer::end_tag('td'); echo html_writer::start_tag('td', array('align' => 'center', 'id' => 'user2')); - echo $OUTPUT->user_picture($user2, array('size' => 100, 'courseid' => SITEID)); + // Show user picture with link is real user else without link. + if (core_user::is_real_user($user2->id)) { + echo $OUTPUT->user_picture($user2, array('size' => 100, 'courseid' => SITEID)); + } else { + echo $OUTPUT->user_picture($user2, array('size' => 100, 'courseid' => SITEID, 'link' => false)); + } echo html_writer::tag('div', fullname($user2), array('class' => 'heading')); if ($showactionlinks && isset($user2->iscontact) && isset($user2->isblocked)) { @@ -2156,8 +2172,11 @@ function message_print_contactlist_user($contact, $incontactlist = true, $isbloc $strcontact = $strblock = $strhistory = null; if ($showactionlinks) { - $strcontact = message_get_contact_add_remove_link($incontactlist, $isblocked, $contact); - $strblock = message_get_contact_block_link($incontactlist, $isblocked, $contact); + // Show block and delete links if user is real user. + if (core_user::is_real_user($contact->id)) { + $strcontact = message_get_contact_add_remove_link($incontactlist, $isblocked, $contact); + $strblock = message_get_contact_block_link($incontactlist, $isblocked, $contact); + } $strhistory = message_history_link($USER->id, $contact->id, true, '', '', 'icon'); }