From 0802c38a2fca2494940e8d2e732162b4f9af930c Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Fri, 9 Nov 2018 14:18:15 +0800 Subject: [PATCH] MDL-63303 message: add lastmessagedate to messagearea contact --- message/classes/helper.php | 3 +++ message/classes/output/messagearea/contact.php | 7 +++++++ message/externallib.php | 1 + 3 files changed, 11 insertions(+) diff --git a/message/classes/helper.php b/message/classes/helper.php index 38b4e554030..8eef5fe7685 100644 --- a/message/classes/helper.php +++ b/message/classes/helper.php @@ -306,11 +306,13 @@ class helper { // Store the message if we have it. $data->ismessaging = false; $data->lastmessage = null; + $data->lastmessagedate = null; $data->messageid = null; if (isset($contact->smallmessage)) { $data->ismessaging = true; // Strip the HTML tags from the message for displaying in the contact area. $data->lastmessage = clean_param($contact->smallmessage, PARAM_NOTAGS); + $data->lastmessagedate = $contact->timecreated; $data->useridfrom = $contact->useridfrom; if (isset($contact->messageid)) { $data->messageid = $contact->messageid; @@ -608,6 +610,7 @@ class helper { $data->profileimageurlsmall = $conv->members[$otheruser->id]->profileimageurlsmall; $data->ismessaging = isset($conv->messages[0]->text) ? true : false; $data->lastmessage = $conv->messages[0]->text ? clean_param($conv->messages[0]->text, PARAM_NOTAGS) : null; + $data->lastmessagedate = $conv->messages[0]->timecreated ?? null; $data->messageid = $conv->messages[0]->id ?? null; $data->isonline = $conv->members[$otheruser->id]->isonline ?? null; $data->isblocked = $conv->members[$otheruser->id]->isblocked ?? null; diff --git a/message/classes/output/messagearea/contact.php b/message/classes/output/messagearea/contact.php index 2f0b504a23a..3a138c1250b 100644 --- a/message/classes/output/messagearea/contact.php +++ b/message/classes/output/messagearea/contact.php @@ -83,6 +83,11 @@ class contact implements templatable, renderable { */ public $lastmessage; + /** + * @var int The last message sent timestamp. + */ + public $lastmessagedate; + /** * @var bool Is the user online? */ @@ -117,6 +122,7 @@ class contact implements templatable, renderable { $this->messageid = $contact->messageid; $this->ismessaging = $contact->ismessaging; $this->lastmessage = $contact->lastmessage; + $this->lastmessagedate = $contact->lastmessagedate; $this->isonline = $contact->isonline; $this->isblocked = $contact->isblocked; $this->isread = $contact->isread; @@ -140,6 +146,7 @@ class contact implements templatable, renderable { } else { $contact->lastmessage = null; } + $contact->lastmessagedate = $this->lastmessagedate; $contact->showonlinestatus = is_null($this->isonline) ? false : true; $contact->isonline = $this->isonline; $contact->isblocked = $this->isblocked; diff --git a/message/externallib.php b/message/externallib.php index 07d01d58005..ddc5e12d0c0 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -1033,6 +1033,7 @@ class core_message_external extends external_api { 'ismessaging' => new external_value(PARAM_BOOL, 'If we are messaging the user'), 'sentfromcurrentuser' => new external_value(PARAM_BOOL, 'Was the last message sent from the current user?'), 'lastmessage' => new external_value(PARAM_NOTAGS, 'The user\'s last message'), + 'lastmessagedate' => new external_value(PARAM_INT, 'Timestamp for last message', VALUE_DEFAULT, null), 'messageid' => new external_value(PARAM_INT, 'The unique search message id', VALUE_DEFAULT, null), 'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'), 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'),