From 18f8f8858c92d11806bf08d5c1125f562f7871b2 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 23 Jan 2020 14:59:52 -0700 Subject: [PATCH] Don't list every single alias when there's many --- src/TextForEvent.js | 24 ++++++++++++++++++++++++ src/i18n/strings/en_EN.json | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/TextForEvent.js b/src/TextForEvent.js index a0d088affb..6a2744109b 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -275,6 +275,8 @@ function textForRoomAliasesEvent(ev) { // This feels a bit overkill though, and it's not clear the i18n really needs it // so instead it's landing as a simple textual event. + const maxShown = 3; + const senderName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); const oldAliases = ev.getPrevContent().aliases || []; const newAliases = ev.getContent().aliases || []; @@ -287,18 +289,40 @@ function textForRoomAliasesEvent(ev) { } if (addedAliases.length && !removedAliases.length) { + if (addedAliases.length > maxShown) { + return _t("%(senderName)s added %(addedAddresses)s and %(count)s other addresses to this room", { + senderName: senderName, + count: addedAliases.length - maxShown, + addedAddresses: addedAliases.slice(0, maxShown).join(', '), + }); + } return _t('%(senderName)s added %(count)s %(addedAddresses)s as addresses for this room.', { senderName: senderName, count: addedAliases.length, addedAddresses: addedAliases.join(', '), }); } else if (!addedAliases.length && removedAliases.length) { + if (removedAliases.length > maxShown) { + return _t("%(senderName)s removed %(removedAddresses)s and %(count)s other addresses from this room", { + senderName: senderName, + count: removedAliases.length - maxShown, + removedAddresses: removedAliases.slice(0, maxShown).join(', '), + }); + } return _t('%(senderName)s removed %(count)s %(removedAddresses)s as addresses for this room.', { senderName: senderName, count: removedAliases.length, removedAddresses: removedAliases.join(', '), }); } else { + const combined = addedAliases.length + removedAliases.length; + if (combined > maxShown) { + return _t("%(senderName)s removed %(countRemoved)s and added %(countAdded)s addresses to this room", { + senderName: senderName, + countAdded: addedAliases.length, + countRemoved: removedAliases.length, + }); + } return _t( '%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.', { senderName: senderName, diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 9060279e54..c86640132a 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -235,10 +235,13 @@ "%(senderDisplayName)s disabled flair for %(groups)s in this room.": "%(senderDisplayName)s disabled flair for %(groups)s in this room.", "%(senderDisplayName)s enabled flair for %(newGroups)s and disabled flair for %(oldGroups)s in this room.": "%(senderDisplayName)s enabled flair for %(newGroups)s and disabled flair for %(oldGroups)s in this room.", "%(senderDisplayName)s sent an image.": "%(senderDisplayName)s sent an image.", + "%(senderName)s added %(addedAddresses)s and %(count)s other addresses to this room|other": "%(senderName)s added %(addedAddresses)s and %(count)s other addresses to this room", "%(senderName)s added %(count)s %(addedAddresses)s as addresses for this room.|other": "%(senderName)s added %(addedAddresses)s as addresses for this room.", "%(senderName)s added %(count)s %(addedAddresses)s as addresses for this room.|one": "%(senderName)s added %(addedAddresses)s as an address for this room.", + "%(senderName)s removed %(removedAddresses)s and %(count)s other addresses from this room|other": "%(senderName)s removed %(removedAddresses)s and %(count)s other addresses from this room", "%(senderName)s removed %(count)s %(removedAddresses)s as addresses for this room.|other": "%(senderName)s removed %(removedAddresses)s as addresses for this room.", "%(senderName)s removed %(count)s %(removedAddresses)s as addresses for this room.|one": "%(senderName)s removed %(removedAddresses)s as an address for this room.", + "%(senderName)s removed %(countRemoved)s and added %(countAdded)s addresses to this room": "%(senderName)s removed %(countRemoved)s and added %(countAdded)s addresses to this room", "%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.": "%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.", "%(senderName)s set the main address for this room to %(address)s.": "%(senderName)s set the main address for this room to %(address)s.", "%(senderName)s removed the main address for this room.": "%(senderName)s removed the main address for this room.",