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.
This commit is contained in:
Jun Pataleta 2018-11-28 16:55:13 +08:00 committed by Ryan Wyllie
parent 030f164ecc
commit 7d82e35e39
4 changed files with 23 additions and 31 deletions

View File

@ -46,7 +46,6 @@ $string['contactblocked'] = 'Contact blocked';
$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';
@ -211,6 +210,7 @@ $string['seeall'] = 'See all';
$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';
@ -251,7 +251,6 @@ $string['viewunreadmessageswith'] = 'View unread messages with {$a}';
$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}';

File diff suppressed because one or more lines are too long

View File

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

View File

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