From eda6bc19e6558cc4ccf0a2e75958f763aa4b8799 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Mon, 18 Jul 2016 06:58:55 +0000 Subject: [PATCH] MDL-54701 message: added isread to data_for_messagearea_conversations --- message/classes/helper.php | 3 ++- message/classes/output/contact.php | 1 + message/externallib.php | 3 ++- message/lib.php | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/message/classes/helper.php b/message/classes/helper.php index d526d52d111..767f13800a6 100644 --- a/message/classes/helper.php +++ b/message/classes/helper.php @@ -146,7 +146,8 @@ class helper { } // Check if the user is online. $data->isonline = $userfields->lastaccess >= $time; + $data->isread = isset($contact->isread) ? $contact->isread : 0; return new \core_message\output\contact($data); } -} \ No newline at end of file +} diff --git a/message/classes/output/contact.php b/message/classes/output/contact.php index 199c2d60142..066c83c753a 100644 --- a/message/classes/output/contact.php +++ b/message/classes/output/contact.php @@ -63,6 +63,7 @@ class contact implements templatable, renderable { $contact->profileimageurlsmall = $this->contact->profileimageurlsmall; $contact->lastmessage = shorten_text($this->contact->lastmessage, self::MAX_MSG_LENGTH); $contact->isonline = $this->contact->isonline; + $contact->isread = $this->contact->isread; return $contact; } diff --git a/message/externallib.php b/message/externallib.php index 39cab93c330..6e917516807 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -485,7 +485,8 @@ class core_message_external extends external_api { 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'), 'lastmessage' => new external_value(PARAM_NOTAGS, 'The user\'s last message', VALUE_OPTIONAL), - 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status', VALUE_OPTIONAL) + 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status', VALUE_OPTIONAL), + 'isread' => new external_value(PARAM_BOOL, 'If the user has read the message', VALUE_OPTIONAL), ) ) ) diff --git a/message/lib.php b/message/lib.php index 82c5040f146..2b7162bfa8f 100644 --- a/message/lib.php +++ b/message/lib.php @@ -342,7 +342,7 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) { $uniquefield = $DB->sql_concat('message.useridfrom', "'-'", 'message.useridto'); $sql = "SELECT $uniquefield, $userfields, message.id as mid, message.notification, message.smallmessage, message.fullmessage, - message.fullmessagehtml, message.fullmessageformat, message.timecreated, + message.fullmessagehtml, message.fullmessageformat, message.timecreated, 1 as isread, contact.id as contactlistid, contact.blocked FROM {message_read} message JOIN ( @@ -389,6 +389,7 @@ function message_get_recent_conversations($user, $limitfrom=0, $limitto=100) { // exact same query as the one above, except for the table we are querying. So, simply replace references to // the 'message_read' table with the 'message' table. $sql = str_replace('{message_read}', '{message}', $sql); + $sql = str_replace('1 as isread', '0 as isread', $sql); $unread = $DB->get_records_sql($sql, $params, $limitfrom, $limitto); // Union the 2 result sets together looking for the message with the most -- 2.17.1