From 3d6668e7f0932860d48fd1ed30dafc74671ce89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 24 Aug 2023 22:42:36 -0400 Subject: [PATCH] fix: dont show chat notif if you are already in the room mark all notifs from chat read when you you mark the chat room read --- public/src/modules/notifications.js | 3 +++ src/api/chats.js | 4 ++++ src/messaging/notifications.js | 1 + 3 files changed, 8 insertions(+) diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index b749c2e068..a983519183 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -90,6 +90,9 @@ define('notifications', [ if (ajaxify.currentPage === 'notifications') { ajaxify.refresh(); } + if (ajaxify.data.template.chats && parseInt(ajaxify.data.roomId, 10) === parseInt(notifData.roomId, 10)) { + return; + } socket.emit('notifications.getCount', function (err, count) { if (err) { diff --git a/src/api/chats.js b/src/api/chats.js index cf7bc6c7ee..3b40f92eba 100644 --- a/src/api/chats.js +++ b/src/api/chats.js @@ -6,6 +6,7 @@ const db = require('../database'); const user = require('../user'); const meta = require('../meta'); const messaging = require('../messaging'); +const notifications = require('../notifications'); const plugins = require('../plugins'); const privileges = require('../privileges'); @@ -156,6 +157,9 @@ chatsAPI.mark = async (caller, data) => { } else { await messaging.markRead(caller.uid, roomId); socketHelpers.emitToUids('event:chats.markedAsRead', { roomId: roomId }, [caller.uid]); + const nids = await user.notifications.getUnreadByField(caller.uid, 'roomId', [roomId]); + await notifications.markReadMultiple(nids, caller.uid); + user.notifications.pushCount(caller.uid); } socketHelpers.emitToUids('event:chats.mark', { roomId, state }, [caller.uid]); diff --git a/src/messaging/notifications.js b/src/messaging/notifications.js index b790649416..ff1f98697f 100644 --- a/src/messaging/notifications.js +++ b/src/messaging/notifications.js @@ -128,6 +128,7 @@ module.exports = function (Messaging) { bodyLong: messageObj.content, nid: `chat_${roomId}_${fromUid}`, from: fromUid, + roomId: roomId, path: `/chats/${messageObj.roomId}`, }; if (roomData.public) {