From 063de7d7159282117efd1a8a2e11e5196e2d9bbf Mon Sep 17 00:00:00 2001 From: Luciano Marcos Pierdona Junior <64279791+LucianoPierdona@users.noreply.github.com> Date: Thu, 25 Aug 2022 01:34:36 -0300 Subject: [PATCH] [FIX] Active users count on `@all` and `@here` (#25957) Co-authored-by: Matheus Barbosa Silva <36537004+matheusbsilva137@users.noreply.github.com> --- apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js | 2 +- apps/meteor/app/models/server/models/Users.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js index 7d2e2b1d8def..4574788a58c9 100644 --- a/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js +++ b/apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.js @@ -244,7 +244,7 @@ export async function sendMessageNotifications(message, room, usersInThread = [] // Don't fetch all users if room exceeds max members const maxMembersForNotification = settings.get('Notifications_Max_Room_Members'); - const roomMembersCount = Subscriptions.findByRoomId(room._id).count(); + const roomMembersCount = await Users.countRoomMembers(room._id); const disableAllMessageNotifications = roomMembersCount > maxMembersForNotification && maxMembersForNotification !== 0; const query = { diff --git a/apps/meteor/app/models/server/models/Users.js b/apps/meteor/app/models/server/models/Users.js index 553a909233d1..a54a201e79b1 100644 --- a/apps/meteor/app/models/server/models/Users.js +++ b/apps/meteor/app/models/server/models/Users.js @@ -1655,6 +1655,10 @@ Find users to send a message by email if: }, }); } + + countRoomMembers(roomId) { + return this.find({ __rooms: roomId, active: true }).count(); + } } export default new Users(Meteor.users, true);