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

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

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

View File

@@ -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'),

View File

@@ -1,5 +1,5 @@
<div class="row-fluid contact {{#selected}}selected{{/selected}} {{#lastmessage}}{{^isread}}unread{{/isread}}{{/lastmessage}}"
data-action="{{#lastmessage}}view-contact-msg{{/lastmessage}}{{^lastmessage}}view-contact-profile{{/lastmessage}}"
data-action="{{#ismessaging}}view-contact-msg{{/ismessaging}}{{^ismessaging}}view-contact-profile{{/ismessaging}}"
data-userid="{{userid}}" data-messageid="{{#messageid}}{{.}}{{isread}}{{/messageid}}" data-region="contact" tabindex="0">
<div class="span3 picture">
<img src="{{profileimageurl}}" alt="" />