MDL-55811 core_message: ensure contact always shown

This commit is contained in:
Mark Nelson
2016-09-01 18:12:47 +08:00
parent dd0c1403a1
commit 5bf0ff278a
5 changed files with 17 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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;
}