From 4dbb9f144659fbc49879213d313ccbfc86b8d4c6 Mon Sep 17 00:00:00 2001 From: Sergey Volkov <5180915+Sergey-Volkov@users.noreply.github.com> Date: Tue, 26 May 2020 13:39:12 +0300 Subject: [PATCH] DEV-4846 Prevent starting a conversation with users in other store groups (#9) --- app/ui-message/client/popup/messagePopupConfig.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/ui-message/client/popup/messagePopupConfig.js b/app/ui-message/client/popup/messagePopupConfig.js index 58a13af0915c..cf8cd010f844 100644 --- a/app/ui-message/client/popup/messagePopupConfig.js +++ b/app/ui-message/client/popup/messagePopupConfig.js @@ -224,6 +224,8 @@ Template.messagePopupConfig.helpers({ // If needed, add to list the online users if (items.length < 5 && filterRegex) { + const user = Meteor.users.findOne(Meteor.userId(), { fields: { username: 1, 'customFields.groupId': 1 } }); + const { customFields: { groupId } = {} } = user || {}; const usernamesAlreadyFetched = items.map(({ username }) => username); if (!hasAllPermission('view-outside-room')) { const usernamesFromDMs = Subscriptions @@ -255,6 +257,9 @@ Template.messagePopupConfig.helpers({ username: { $in: usernamesFromDMs, }, + 'customFields.groupId': { + $in: [groupId, null], + }, }, { fields: { @@ -276,7 +281,6 @@ Template.messagePopupConfig.helpers({ items.push(...newItems); } else { - const user = Meteor.users.findOne(Meteor.userId(), { fields: { username: 1, 'customFields.groupId': 1 } }); const newItems = Meteor.users.find({ $and: [ { @@ -296,7 +300,9 @@ Template.messagePopupConfig.helpers({ }, }, { - groupId: { $in: [user && user.customFields && user.customFields.groupId, null] }, + 'customFields.groupId': { + $in: [groupId, null], + }, }, ], },