From 32cad6dc82dce2334cf23372f6dfdc084c22ef97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 12 Jan 2023 13:32:39 -0500 Subject: [PATCH] feat: add new language string for chat usernames --- public/language/en-GB/modules.json | 1 + src/messaging/index.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) 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);