From b068161c9ead97bc11dc56eb381994803b318f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20J=C3=A4gle?= Date: Tue, 18 Sep 2018 21:35:30 +0200 Subject: [PATCH] [Threading] Configure limit of max invited users --- packages/assistify-threading/config.js | 8 ++++++++ .../assistify-threading/server/methods/createThread.js | 7 ++++++- packages/rocketchat-i18n/i18n/de.i18n.json | 2 ++ packages/rocketchat-i18n/i18n/en.i18n.json | 2 ++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/assistify-threading/config.js b/packages/assistify-threading/config.js index ad595a6f0367..ea0ef8d7a85f 100644 --- a/packages/assistify-threading/config.js +++ b/packages/assistify-threading/config.js @@ -37,6 +37,14 @@ Meteor.startup(() => { RocketChat.models.Settings.updateValueById('Thread_default_parent_Channel', defaultChannel); } + RocketChat.settings.add('Thread_invitations_threshold', 10, { + group: 'Threading', + i18nLabel: 'Thread_invitations_threshold', + i18nDescription: 'Thread_invitations_threshold_description', + type: 'int', + public: true + }); + RocketChat.settings.add('Thread_from_context_menu', 'button', { group: 'Threading', i18nLabel: 'Thread_from_context_menu', diff --git a/packages/assistify-threading/server/methods/createThread.js b/packages/assistify-threading/server/methods/createThread.js index 4b17b6c61d87..408c059956c9 100644 --- a/packages/assistify-threading/server/methods/createThread.js +++ b/packages/assistify-threading/server/methods/createThread.js @@ -121,6 +121,7 @@ export class ThreadBuilder { _getMembers() { const checkRoles = ['owner', 'moderator', 'leader']; + const maxInvitationCount = Math.max(RocketChat.models.Settings.findOneById('Thread_invitations_threshold').value, 0) || 0; let members = []; const admins = RocketChat.models.Subscriptions.findByRoomIdAndRoles(this._parentRoomId, checkRoles).fetch().map(s => { return { @@ -131,6 +132,10 @@ export class ThreadBuilder { fields: { 'u._id': 1, 'u.username': 1 + }, + sort: { + open: -1, + ls: -1 } }).fetch().map(s => { return { @@ -140,7 +145,7 @@ export class ThreadBuilder { }); if (this._parentRoom.t === 'c') { // only add online users - members = RocketChat.models.Users.findUsersWithUsernameByIdsNotOffline(users.map(user=>user.id)).fetch().map(user=>user.username); + members = RocketChat.models.Users.findUsersWithUsernameByIdsNotOffline(users.slice(0, maxInvitationCount).map(user=>user.id)).fetch().map(user=>user.username); // add admins to the member list and avoid duplicates members = Array.from(new Set(members.concat(admins.map(user=>user.username)))); } else { diff --git a/packages/rocketchat-i18n/i18n/de.i18n.json b/packages/rocketchat-i18n/i18n/de.i18n.json index 0d733931053f..27139fbddef4 100644 --- a/packages/rocketchat-i18n/i18n/de.i18n.json +++ b/packages/rocketchat-i18n/i18n/de.i18n.json @@ -2527,6 +2527,8 @@ "thread-welcome" : "Danke __username__, dass Du einen neuen Thread angelegt hast! Ich habe für Dich Mitglieder aus __parentChannel__ eingeladen. Tipp: mit \"@all\" kannst Du sie anstupsen, wenn sich länger niemand melden sollte ;)", "Threading_description": "Erstelle einen Thread, um wichtigen Dingen mehr Raum zu geben. Dort kannst Du mit allen verfügbaren Mitgliedern schreiben, ohne andere zu stören. So sorgst Du für etwas mehr Ordnung in Eurem Chat.", "Thread_from_context_menu": "Threads im Kontext-Menü", + "Thread_invitations_threshold": "Max. Anzahl automatisch einzuladender Benutzer", + "Thread_invitations_threshold_description": "Max. Anzahl der Benutzer, die automatisch zu einem öffentlichen Thread hinzugezogen werden", "Threading_context_menu_button": "Separater Button", "Threading_context_menu_none": "Unsichtbar", "Thread_creation_on_home": "Threads von der Home-Seite aus anlegen", diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 46986b2d6180..6e4720697e56 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -2514,6 +2514,8 @@ "thread-created" : "I started a new __channelLink__", "thread-welcome" : "Thanks __username__ for creating a thread! I invited some members from __parentChannel__ who shall be able to help you. Hint: You can poke them with \"@all\", in case there's nothing happening for a longer time ;)", "Thread_from_context_menu": "Threads in context-menu", + "Thread_invitations_threshold": "Max. users to be automatically invited", + "Thread_invitations_threshold_description": "Max. count of users who are automatically being invited into a public thread", "Threading_context_menu_button": "Dedicated button", "Threading_context_menu_none": "Invisible", "Threading_description": "Help keeping an overview about what's going on! By creating a thread, a sub-channel of the one you selected is created and both are linked.",