Skip to content

Commit

Permalink
fix: suppress chat message notifications for users who are known to b…
Browse files Browse the repository at this point in the history
…e in the chat room (uid is present in the corresponding socket.io room)
  • Loading branch information
julianlam committed Oct 25, 2023
1 parent 5d7c10f commit 18c27d1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/messaging/notifications.js
Expand Up @@ -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(
Expand All @@ -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);
Expand Down

0 comments on commit 18c27d1

Please sign in to comment.