From 0a4f984cf561e7ae354da5151615eaba9b9d0324 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 21 Nov 2017 16:38:13 -0800 Subject: [PATCH] Properly localize group changes (#1802) * Properly localize group updates * Remove phone number in display name if contact in address book * New string for multiple new group members --- _locales/en/messages.json | 14 ++++++++++++-- js/models/conversations.js | 18 ++++++++++++++++++ js/models/messages.js | 22 ++++++++++++++++++---- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 171af17f4..46b7bd4a4 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -906,7 +906,7 @@ }, "leftTheGroup": { "message": "$name$ left the group.", - "description": "Shown in the conversation history when someone leaves the group", + "description": "Shown in the conversation history when a single person leaves the group", "placeholders": { "name": { "content": "$1", @@ -929,8 +929,18 @@ } }, "joinedTheGroup": { + "message": "$name$ joined the group.", + "description": "Shown in the conversation history when a single person joins the group", + "placeholders": { + "name": { + "content": "$1", + "example": "Alice" + } + } + }, + "multipleJoinedTheGroup": { "message": "$names$ joined the group.", - "description": "Shown in the conversation history when people join the group", + "description": "Shown in the conversation history when more than one person joins the group", "placeholders": { "names": { "content": "$1", diff --git a/js/models/conversations.js b/js/models/conversations.js index 6a063ac31..2b0e7d13b 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1017,6 +1017,24 @@ } }, + getDisplayName: function() { + if (!this.isPrivate()) { + return this.getTitle(); + } + + var name = this.get('name'); + if (name) { + return name; + } + + var profileName = this.get('profileName'); + if (profileName) { + return this.getNumber() + ' ~' + profileName; + } + + return this.getNumber(); + }, + getNumber: function() { if (!this.isPrivate()) { return ''; diff --git a/js/models/messages.js b/js/models/messages.js index 89c8cc297..76732958c 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -72,19 +72,33 @@ return this.sync('read', this, options); }, // jscs:enable + getNameForNumber: function(number) { + var conversation = ConversationController.get(number); + if (!conversation) { + return number; + } + return conversation.getDisplayName(); + }, getDescription: function() { if (this.isGroupUpdate()) { var group_update = this.get('group_update'); - if (group_update.left) { - return i18n('leftTheGroup', group_update.left); + if (group_update.left === 'You') { + return i18n('youLeftTheGroup'); + } else if (group_update.left) { + return i18n('leftTheGroup', this.getNameForNumber(group_update.left)); } var messages = [i18n('updatedTheGroup')]; if (group_update.name) { messages.push(i18n('titleIsNow', group_update.name)); } - if (group_update.joined) { - messages.push(i18n('joinedTheGroup', group_update.joined.join(', '))); + if (group_update.joined && group_update.joined.length) { + var names = _.map(group_update.joined, this.getNameForNumber.bind(this)); + if (names.length > 1) { + messages.push(i18n('multipleJoinedTheGroup', names.join(', '))); + } else { + messages.push(i18n('joinedTheGroup', names[0])); + } } return messages.join(' ');