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)

This commit is contained in:
Julian Lam
2023-10-25 12:02:28 -04:00
parent 5d7c10f128
commit 18c27d1ad3

View File

@@ -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);