mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-55623 core_message: indicate who the message is from
This commit is contained in:
parent
94e1db613c
commit
89a70ba1a5
@ -187,3 +187,4 @@ $string['userssearchresults'] = 'Users found: {$a}';
|
||||
$string['viewinganotherusersmessagearea'] = 'You are viewing another user\'s message area.';
|
||||
$string['viewconversation'] = 'View conversation';
|
||||
$string['writeamessage'] = 'Write a message...';
|
||||
$string['you'] = 'You:';
|
||||
|
@ -50,7 +50,9 @@ define(['jquery', 'core_message/message_area_contacts', 'core_message/message_ar
|
||||
DELETEMESSAGES: "[data-action='delete-messages']",
|
||||
DELETEMESSAGECHECKBOX: "[data-region='delete-message-checkbox']",
|
||||
DELETESEARCHFILTER: "[data-action='search-filter-delete']",
|
||||
LASTMESSAGE: '.lastmessage',
|
||||
LASTMESSAGEAREA: "[data-region='last-message-area']",
|
||||
LASTMESSAGEUSER: "[data-region='last-message-user']",
|
||||
LASTMESSAGETEXT: "[data-region='last-message-text']",
|
||||
LOADINGICON: '.loading-icon',
|
||||
MENU: "[data-region='menu']",
|
||||
MESSAGE: "[data-region='message']",
|
||||
|
@ -21,8 +21,8 @@
|
||||
* @copyright 2016 Mark Nelson <markn@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/custom_interaction_events'],
|
||||
function($, ajax, templates, notification, customEvents) {
|
||||
define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/custom_interaction_events', 'core/str'],
|
||||
function($, ajax, templates, notification, customEvents, Str) {
|
||||
|
||||
/**
|
||||
* Contacts class.
|
||||
@ -171,8 +171,6 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
Contacts.prototype._handleMessageSent = function(event, userid, text) {
|
||||
// Switch to viewing the conversations.
|
||||
this._viewConversations();
|
||||
// Get the text we will display on the contact panel.
|
||||
text = this._getContactText(text);
|
||||
// Get the user node.
|
||||
var user = this._getUserNode(this.messageArea.SELECTORS.CONVERSATIONS, userid);
|
||||
// If the user has not been loaded yet, let's copy the element from contact or search panel to the conversation panel.
|
||||
@ -200,8 +198,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
user.prependTo(this.messageArea.find(this.messageArea.SELECTORS.CONVERSATIONS));
|
||||
// Scroll to the top.
|
||||
this.messageArea.find(this.messageArea.SELECTORS.CONVERSATIONS).scrollTop(0);
|
||||
// Replace the text.
|
||||
user.find(this.messageArea.SELECTORS.LASTMESSAGE).empty().append(text);
|
||||
// Get the new text to show.
|
||||
this._updateContactText(user, text, true);
|
||||
// Ensure user is selected.
|
||||
this._setSelectedUser("[data-userid='" + userid + "']");
|
||||
};
|
||||
@ -373,7 +371,6 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
}
|
||||
}]);
|
||||
|
||||
// After the request render the contacts area.
|
||||
return promises[0];
|
||||
};
|
||||
|
||||
@ -407,10 +404,11 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
* Handles deleting conversations.
|
||||
*
|
||||
* @params {Event} event
|
||||
* @params {int} The user id belonging to the messages we are deleting.
|
||||
* @params {int} The user id belonging to the messages we are deleting
|
||||
* @params {jQuery|null} The message we need to update the contact panel with
|
||||
* @private
|
||||
*/
|
||||
Contacts.prototype._deleteConversations = function(event, userid) {
|
||||
Contacts.prototype._deleteConversations = function(event, userid, updatemessage) {
|
||||
var checkboxes = this.messageArea.find(this.messageArea.SELECTORS.CONTACT + "[aria-checked='true']");
|
||||
var requests = [];
|
||||
|
||||
@ -435,30 +433,21 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
this._numConversationsDisplayed--;
|
||||
// Trigger conversation deleted events.
|
||||
this.messageArea.trigger(this.messageArea.EVENTS.CONVERSATIONDELETED, requests[i].args.otheruserid);
|
||||
|
||||
}
|
||||
}.bind(this), notification.exception);
|
||||
}
|
||||
|
||||
// Check if the last message needs updating.
|
||||
var user = this._getUserNode(this.messageArea.SELECTORS.CONVERSATIONS, userid);
|
||||
if (user.length !== 0) {
|
||||
var lastmessagelisted = user.find(this.messageArea.SELECTORS.LASTMESSAGE);
|
||||
lastmessagelisted = lastmessagelisted.html();
|
||||
// Go through and get the actual last message after all the deletions.
|
||||
var messages = this.messageArea.find(this.messageArea.SELECTORS.MESSAGESAREA + " " +
|
||||
this.messageArea.SELECTORS.MESSAGE);
|
||||
var messageslength = messages.length;
|
||||
if (updatemessage) {
|
||||
var user = this._getUserNode(this.messageArea.SELECTORS.CONVERSATIONS, userid);
|
||||
var updatemessagetext = updatemessage.find(this.messageArea.SELECTORS.MESSAGETEXT).text().trim();
|
||||
var sentbyuser = false;
|
||||
if (updatemessage.data('useridto') == userid) {
|
||||
// Must have been sent by the currently logged in user.
|
||||
sentbyuser = true;
|
||||
}
|
||||
|
||||
messages.each(function(index, element) {
|
||||
if (index === messageslength - 1) {
|
||||
var actuallastmessage = $(element).find(this.messageArea.SELECTORS.MESSAGETEXT).html().trim();
|
||||
if (lastmessagelisted != actuallastmessage) {
|
||||
user.find(this.messageArea.SELECTORS.LASTMESSAGE).empty().append(
|
||||
this._getContactText(actuallastmessage));
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
this._updateContactText(user, updatemessagetext, sentbyuser);
|
||||
}
|
||||
|
||||
// Now we have done all the deletion we can set the flag back to false.
|
||||
@ -565,6 +554,30 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
return text;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles updating the contact text.
|
||||
*
|
||||
* @param {jQuery} user The user to update
|
||||
* @param {String} text The text to update the contact with
|
||||
* @param {Boolean} sentbyuser Was it sent by the currently logged in user?
|
||||
* @private
|
||||
*/
|
||||
Contacts.prototype._updateContactText = function(user, text, sentbyuser) {
|
||||
// Get the text we will display on the contact panel.
|
||||
text = this._getContactText(text);
|
||||
if (sentbyuser) {
|
||||
Str.get_string('you', 'message').done(function (string) {
|
||||
// Ensure we display that the message is from this user.
|
||||
user.find(this.messageArea.SELECTORS.LASTMESSAGEUSER).empty().append(string);
|
||||
}.bind(this)).always(function () {
|
||||
user.find(this.messageArea.SELECTORS.LASTMESSAGETEXT).empty().append(text);
|
||||
}.bind(this));
|
||||
} else {
|
||||
user.find(this.messageArea.SELECTORS.LASTMESSAGEUSER).empty();
|
||||
user.find(this.messageArea.SELECTORS.LASTMESSAGETEXT).empty().append(text);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Shifts focus to the next contact in the list.
|
||||
*
|
||||
|
@ -329,11 +329,20 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
|
||||
if (requests.length > 0) {
|
||||
ajax.call(requests)[requests.length - 1].then(function() {
|
||||
// Store the last message on the page, and the last message being deleted.
|
||||
var updatemessage = null;
|
||||
var messages = this.messageArea.find(this.messageArea.SELECTORS.MESSAGE);
|
||||
var lastmessage = messages.last();
|
||||
var lastremovedmessage = messagestoremove[messagestoremove.length - 1];
|
||||
// Remove the messages from the DOM.
|
||||
$.each(messagestoremove, function(key, message) {
|
||||
// Remove the message.
|
||||
message.remove();
|
||||
});
|
||||
// If the last message was deleted then we need to provide the new last message.
|
||||
if (lastmessage.data('id') === lastremovedmessage.data('id')) {
|
||||
updatemessage = this.messageArea.find(this.messageArea.SELECTORS.MESSAGE).last();
|
||||
}
|
||||
// Now we have removed all the messages from the DOM lets remove any block times we may need to as well.
|
||||
$.each(messagestoremove, function(key, message) {
|
||||
// First - let's make sure there are no more messages in that time block.
|
||||
@ -352,7 +361,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/cust
|
||||
}
|
||||
|
||||
// Trigger event letting other modules know messages were deleted.
|
||||
this.messageArea.trigger(this.messageArea.EVENTS.MESSAGESDELETED, this._getUserId());
|
||||
this.messageArea.trigger(this.messageArea.EVENTS.MESSAGESDELETED, [this._getUserId(), updatemessage]);
|
||||
}.bind(this), notification.exception);
|
||||
} else {
|
||||
// Trigger event letting other modules know messages were deleted.
|
||||
|
@ -132,6 +132,7 @@ class helper {
|
||||
$userfields = \user_picture::unalias($contact, array('lastaccess'), $prefix . 'id', $prefix);
|
||||
$data = new \stdClass();
|
||||
$data->userid = $userfields->id;
|
||||
$data->useridfrom = null;
|
||||
$data->fullname = fullname($userfields);
|
||||
// Get the user picture data.
|
||||
$userpicture = new \user_picture($userfields);
|
||||
@ -146,6 +147,7 @@ class helper {
|
||||
if (isset($contact->smallmessage)) {
|
||||
$data->ismessaging = true;
|
||||
$data->lastmessage = $contact->smallmessage;
|
||||
$data->useridfrom = $contact->useridfrom;
|
||||
if (isset($contact->messageid)) {
|
||||
$data->messageid = $contact->messageid;
|
||||
}
|
||||
|
@ -46,6 +46,11 @@ class contact implements templatable, renderable {
|
||||
*/
|
||||
public $userid;
|
||||
|
||||
/**
|
||||
* @var int The id of the user who sent the last message.
|
||||
*/
|
||||
public $useridfrom;
|
||||
|
||||
/**
|
||||
* @var string The fullname.
|
||||
*/
|
||||
@ -103,6 +108,7 @@ class contact implements templatable, renderable {
|
||||
*/
|
||||
public function __construct($contact) {
|
||||
$this->userid = $contact->userid;
|
||||
$this->useridfrom = $contact->useridfrom;
|
||||
$this->fullname = $contact->fullname;
|
||||
$this->profileimageurl = $contact->profileimageurl;
|
||||
$this->profileimageurlsmall = $contact->profileimageurlsmall;
|
||||
@ -123,7 +129,11 @@ class contact implements templatable, renderable {
|
||||
$contact->profileimageurlsmall = $this->profileimageurlsmall;
|
||||
$contact->messageid = $this->messageid;
|
||||
$contact->ismessaging = $this->ismessaging;
|
||||
$contact->sentfromcurrentuser = false;
|
||||
if ($this->lastmessage) {
|
||||
if ($this->userid !== $this->useridfrom) {
|
||||
$contact->sentfromcurrentuser = true;
|
||||
}
|
||||
$contact->lastmessage = shorten_text($this->lastmessage, self::MAX_MSG_LENGTH);
|
||||
} else {
|
||||
$contact->lastmessage = null;
|
||||
|
@ -92,8 +92,12 @@ class contacts implements templatable, renderable {
|
||||
$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 = '';
|
||||
$user->useridfrom = $user->id;
|
||||
$contact = \core_message\helper::create_contact($user);
|
||||
$data->contacts[] = $contact->export_for_template($output);
|
||||
$contactdata = $contact->export_for_template($output);
|
||||
$contactdata->selected = true;
|
||||
// Put the contact at the front.
|
||||
array_unshift($data->contacts, $contactdata);
|
||||
}
|
||||
|
||||
$data->isconversation = $this->isconversation;
|
||||
|
@ -46,6 +46,11 @@ class message implements templatable, renderable {
|
||||
*/
|
||||
public $currentuserid;
|
||||
|
||||
/**
|
||||
* @var int The userid to.
|
||||
*/
|
||||
public $useridto;
|
||||
|
||||
/**
|
||||
* @var int The userid from.
|
||||
*/
|
||||
@ -79,6 +84,7 @@ class message implements templatable, renderable {
|
||||
public function __construct($message) {
|
||||
$this->id = $message->id;
|
||||
$this->currentuserid = $message->currentuserid;
|
||||
$this->useridto = $message->useridto;
|
||||
$this->useridfrom = $message->useridfrom;
|
||||
$this->text = $message->text;
|
||||
$this->displayblocktime = $message->displayblocktime;
|
||||
@ -89,6 +95,8 @@ class message implements templatable, renderable {
|
||||
public function export_for_template(\renderer_base $output) {
|
||||
$message = new \stdClass();
|
||||
$message->id = $this->id;
|
||||
$message->useridto = $this->useridto;
|
||||
$message->useridfrom = $this->useridfrom;
|
||||
$message->text = $this->text;
|
||||
$message->displayblocktime = $this->displayblocktime;
|
||||
$message->blocktime = userdate($this->timecreated, get_string('strftimedaydate'));
|
||||
|
@ -434,6 +434,7 @@ 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'),
|
||||
'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'),
|
||||
'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'),
|
||||
@ -455,6 +456,8 @@ class core_message_external extends external_api {
|
||||
return new external_single_structure(
|
||||
array(
|
||||
'id' => new external_value(PARAM_INT, 'The id of the message'),
|
||||
'useridfrom' => new external_value(PARAM_INT, 'The id of the user who sent the message'),
|
||||
'useridto' => new external_value(PARAM_INT, 'The id of the user who received the message'),
|
||||
'text' => new external_value(PARAM_RAW, 'The text of the message'),
|
||||
'displayblocktime' => new external_value(PARAM_BOOL, 'Should we display the block time?'),
|
||||
'blocktime' => new external_value(PARAM_NOTAGS, 'The time to display above the message'),
|
||||
|
@ -14,10 +14,15 @@
|
||||
{{#pix}} t/block, core, {{#str}} contactblocked, message {{/str}} {{/pix}}
|
||||
</span>
|
||||
</div>
|
||||
<p class="lastmessage" data-region="lastmessage">
|
||||
{{#lastmessage}}
|
||||
{{.}}
|
||||
{{/lastmessage}}
|
||||
<p class="lastmessage" data-region="last-message-area">
|
||||
<span data-region="last-message-user">
|
||||
{{#sentfromcurrentuser}}{{#str}}you, message{{/str}}{{/sentfromcurrentuser}}
|
||||
</span>
|
||||
<span data-region="last-message-text">
|
||||
{{#lastmessage}}
|
||||
{{.}}
|
||||
{{/lastmessage}}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="span2 unread-count-container">
|
||||
|
@ -7,6 +7,8 @@
|
||||
data-region="message"
|
||||
data-blocktime="{{blocktime}}"
|
||||
data-id="{{id}}{{isread}}"
|
||||
data-useridto="{{useridto}}"
|
||||
data-useridfrom="{{useridfrom}}"
|
||||
data-messageid="{{id}}"
|
||||
data-messageread="{{isread}}"
|
||||
tabindex="0">
|
||||
|
@ -48,7 +48,12 @@
|
||||
</div>
|
||||
<div class="content-item-body">
|
||||
<h3>{{fullname}}</h3>
|
||||
<p>{{lastmessage}}</p>
|
||||
<p>
|
||||
{{#sentfromcurrentuser}}
|
||||
<span data-region="last-message-user">{{#str}}you, message{{/str}}</span>
|
||||
{{/sentfromcurrentuser}}
|
||||
{{lastmessage}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="unread-count-container">
|
||||
<span data-region="unread-count" class="badge badge-important">{{unreadcount}}</span>
|
||||
|
Loading…
x
Reference in New Issue
Block a user