From 18c27d1ad35f89973743e541d3633df649d41a79 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 25 Oct 2023 12:02:28 -0400 Subject: [PATCH] fix: suppress chat message notifications for users who are known to be in the chat room (uid is present in the corresponding socket.io room) --- src/messaging/notifications.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/messaging/notifications.js b/src/messaging/notifications.js index 2dc78a03d4..81a784944f 100644 --- a/src/messaging/notifications.js +++ b/src/messaging/notifications.js @@ -84,7 +84,7 @@ module.exports = function (Messaging) { Messaging.getRoomData(roomId), ]); const roomDefault = roomData.notificationSetting; - const uidsToNotify = []; + let uidsToNotify = []; const { ALLMESSAGES } = Messaging.notificationSettings; await batch.processSortedSet(`chat:room:${roomId}:uids:online`, async (uids) => { uids = uids.filter( @@ -99,6 +99,10 @@ module.exports = function (Messaging) { interval: 100, }); + // Suppress notifications for users who are literally present in the room + const realtimeUids = await io.getUidsInRoom(`chat_room_${roomId}`); + uidsToNotify = uidsToNotify.filter(uid => !realtimeUids.includes(parseInt(uid, 10))); + if (uidsToNotify.length) { const { displayname } = messageObj.fromUser; const isGroupChat = await Messaging.isGroupChat(roomId);