diff --git a/public/language/en-GB/modules.json b/public/language/en-GB/modules.json index c8eb1370dd..4e700b2c74 100644 --- a/public/language/en-GB/modules.json +++ b/public/language/en-GB/modules.json @@ -2,6 +2,7 @@ "chat.chatting_with": "Chat with", "chat.placeholder": "Type chat message here, drag & drop images, press enter to send", "chat.scroll-up-alert": "You are looking at older messages, click here to go to most recent message.", + "chat.usernames-and-x-others": "%1 & %2 others", "chat.send": "Send", "chat.no_active": "You have no active chats.", "chat.user_typing": "%1 is typing ...", diff --git a/src/messaging/index.js b/src/messaging/index.js index 6ad192ef7f..f6a0f71e6b 100644 --- a/src/messaging/index.js +++ b/src/messaging/index.js @@ -9,6 +9,7 @@ const privileges = require('../privileges'); const plugins = require('../plugins'); const meta = require('../meta'); const utils = require('../utils'); +const translator = require('../translator'); const Messaging = module.exports; @@ -137,8 +138,18 @@ Messaging.getRecentChats = async (callerUid, uid, start, stop) => { }); }; -Messaging.generateUsernames = (users, excludeUid) => users.filter(user => user && parseInt(user.uid, 10) !== excludeUid) - .map(user => user.username).join(', '); +Messaging.generateUsernames = function (users, excludeUid) { + users = users.filter(u => u && parseInt(u.uid, 10) !== excludeUid); + const usernames = users.map(u => u.username); + if (users.length > 2) { + return translator.compile( + 'modules:chat.usernames-and-x-others', + usernames.slice(0, 2).join(', '), + usernames.length - 2 + ); + } + return usernames.join(', '); +}; Messaging.getTeaser = async (uid, roomId) => { const mid = await Messaging.getLatestUndeletedMessage(uid, roomId);