diff --git a/message/classes/helper.php b/message/classes/helper.php index 448df7a6c65..eac8c30fc41 100644 --- a/message/classes/helper.php +++ b/message/classes/helper.php @@ -140,9 +140,11 @@ class helper { $userpicture->size = 0; // Size f2. $data->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false); // Store the message if we have it. + $data->ismessaging = false; $data->lastmessage = null; $data->messageid = null; if (isset($contact->smallmessage)) { + $data->ismessaging = true; $data->lastmessage = $contact->smallmessage; if (isset($contact->messageid)) { $data->messageid = $contact->messageid; diff --git a/message/classes/output/messagearea/contact.php b/message/classes/output/messagearea/contact.php index 7ccfab2af3d..1a301da520a 100644 --- a/message/classes/output/messagearea/contact.php +++ b/message/classes/output/messagearea/contact.php @@ -69,6 +69,7 @@ class contact implements templatable, renderable { $contact->profileimageurl = $this->contact->profileimageurl; $contact->profileimageurlsmall = $this->contact->profileimageurlsmall; $contact->messageid = $this->contact->messageid; + $contact->ismessaging = $this->contact->ismessaging; if ($this->contact->lastmessage) { $contact->lastmessage = shorten_text($this->contact->lastmessage, self::MAX_MSG_LENGTH); } else { diff --git a/message/classes/output/messagearea/contacts.php b/message/classes/output/messagearea/contacts.php index 05b0ccdb931..0a80e298cb7 100644 --- a/message/classes/output/messagearea/contacts.php +++ b/message/classes/output/messagearea/contacts.php @@ -92,14 +92,26 @@ class contacts implements templatable, renderable { $data->userid = $this->userid; $data->otheruserid = $this->otheruserid; $data->contacts = array(); + $userids = array(); foreach ($this->contacts as $contact) { $contactdata = $contact->export_for_template($output); + $userids[$contactdata->userid] = $contactdata->userid; // Check if the contact was selected. if ($this->otheruserid == $contactdata->userid) { $contactdata->selected = true; } $data->contacts[] = $contactdata; } + // Check if the other user is not part of the contacts. We may be sending a message to someone + // we have not had a conversation with, so we want to add a new item to the contacts array. + if ($this->otheruserid && !isset($userids[$this->otheruserid])) { + $user = \core_user::get_user($this->otheruserid); + // Set an empty message so that we know we are messaging the user, and not viewing their profile. + $user->smallmessage = ''; + $contact = \core_message\helper::create_contact($user); + $data->contacts[] = $contact->export_for_template($output); + } + $data->isconversation = $this->isconversation; return $data; } diff --git a/message/externallib.php b/message/externallib.php index 2fb75bd0cca..4d916fe2ac1 100644 --- a/message/externallib.php +++ b/message/externallib.php @@ -433,6 +433,7 @@ class core_message_external extends external_api { 'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'), + 'ismessaging' => new external_value(PARAM_BOOL, 'If we are messaging the user'), 'lastmessage' => new external_value(PARAM_NOTAGS, 'The user\'s last message'), 'messageid' => new external_value(PARAM_INT, 'The unique search message id', VALUE_DEFAULT, null), 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'), diff --git a/message/templates/message_area_contact.mustache b/message/templates/message_area_contact.mustache index ed4cb6de062..beaa4f04d20 100644 --- a/message/templates/message_area_contact.mustache +++ b/message/templates/message_area_contact.mustache @@ -1,5 +1,5 @@