Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDL-64245 message: Ditch sender+lastmessage lang string for simplicity
Passing the last message (which can virtually contain any character) as
a parameter for the {{#str}} mustache helper can break the JSON parsing
which eventually leads to the breakage of the messaging UI.
So for simplicity, revert the addition of the 'conversationlastmessage'
language string and render the sender and the last message as separate
elements.
  • Loading branch information
junpataleta authored and ryanwyllie committed Nov 29, 2018
1 parent 030f164 commit 7d82e35
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
3 changes: 1 addition & 2 deletions lang/en/message.php
Expand Up @@ -46,7 +46,6 @@
$string['contactrequests'] = 'Contact requests';
$string['contactrequestsent'] = 'Contact request sent';
$string['contacts'] = 'Contacts';
$string['conversationlastmessage'] = '{$a->sender}: {$a->message}';
$string['decline'] = 'Decline';
$string['defaultmessageoutputs'] = 'Default message outputs';
$string['defaults'] = 'Defaults';
Expand Down Expand Up @@ -211,6 +210,7 @@
$string['selectmessagestodelete'] = 'Select messages to delete';
$string['selectnotificationtoview'] = 'Select from the list of notifications on the side to view more details';
$string['send'] = 'Send';
$string['sender'] = '{$a}:';
$string['sendingvia'] = 'Sending "{$a->provider}" via "{$a->processor}"';
$string['sendingviawhen'] = 'Sending "{$a->provider}" via "{$a->processor}" when {$a->state}';
$string['sendcontactrequest'] = 'Send contact request';
Expand Down Expand Up @@ -251,7 +251,6 @@
$string['writeamessage'] = 'Write a message...';
$string['wouldliketocontactyou'] = 'Would like to contact you';
$string['you'] = 'You:';
$string['yousender'] = 'You';
$string['youhaveblockeduser'] = 'You have blocked this user in the past';
$string['yourcontactrequestpending'] = 'Your contact request is pending with {$a}';

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions message/amd/src/message_drawer_view_overview_section.js
Expand Up @@ -361,14 +361,21 @@ function(
*/
var updateLastMessage = function(element, conversation) {
var message = conversation.messages[conversation.messages.length - 1];
var youString = '';
var senderString = '';
var senderStringRequest;
if (message.fromLoggedInUser) {
senderStringRequest = {key: 'you', component: 'core_message'};
} else {
senderStringRequest = {key: 'sender', component: 'core_message', param: message.userFrom.fullname};
}

var stringRequests = [
{key: 'yousender', component: 'core_message'},
senderStringRequest,
{key: 'strftimetime24', component: 'core_langconfig'},
];
return Str.get_strings(stringRequests)
.then(function(strings) {
youString = strings[0];
senderString = strings[0];
return UserDate.get([{timestamp: message.timeCreated, format: strings[1]}]);
})
.then(function(dates) {
Expand All @@ -377,13 +384,15 @@ function(
.then(function(dateString) {
element.find(SELECTORS.LAST_MESSAGE_DATE).text(dateString).removeClass('hidden');

// No need to show sender string for private conversations and where the last message didn't come from you.
if (!message.fromLoggedInUser &&
conversation.type === MessageDrawerViewConversationContants.CONVERSATION_TYPES.PRIVATE) {
senderString = '';
}

// Now load the last message.
return Str.get_string('conversationlastmessage', 'core_message', {
sender: message.fromLoggedInUser ? youString : message.userFrom.fullname,
message: "<span class='text-muted'>" + $(message.text).text() + "</span>"
});
})
.then(function(lastMessage) {
var lastMessage = senderString + " <span class='text-muted'>" + $(message.text).text() + "</span>";

return element.find(SELECTORS.LAST_MESSAGE).html(lastMessage);
});
};
Expand Down
22 changes: 3 additions & 19 deletions message/templates/message_drawer_conversations_list.mustache
Expand Up @@ -67,30 +67,14 @@
{{/subname}}
<p class="m-0 font-weight-light text-truncate last-message" data-region="last-message">
{{#sentfromcurrentuser}}
{{#str}}
conversationlastmessage,
core_message,
{
"sender": "{{#str}} yousender, core_message {{/str}}",
"message": "<span class='text-muted'>{{lastmessage}}</span>"
}
{{/str}}
{{#str}} you, core_message {{/str}}
{{/sentfromcurrentuser}}
{{^sentfromcurrentuser}}
{{#lastsendername}}
{{#str}}
conversationlastmessage,
core_message,
{
"sender": "{{.}}",
"message": "<span class='text-muted'>{{lastmessage}}</span>"
}
{{/str}}
{{/lastsendername}}
{{^lastsendername}}
<span class='text-muted'>{{lastmessage}}</span>
{{#str}} sender, core_message, {{.}} {{/str}}
{{/lastsendername}}
{{/sentfromcurrentuser}}
<span class='text-muted'>{{lastmessage}}</span>
</p>
</div>
<div class="d-flex align-self-stretch">
Expand Down

0 comments on commit 7d82e35

Please sign in to comment.