diff --git a/.changeset/calm-rules-dance.md b/.changeset/calm-rules-dance.md new file mode 100644 index 0000000000000..ac0a1e58e0a47 --- /dev/null +++ b/.changeset/calm-rules-dance.md @@ -0,0 +1,6 @@ +--- +"@rocket.chat/meteor": patch +"@rocket.chat/model-typings": patch +--- + +Fixed issue with notifications for thread messages still being sent after thread has been read diff --git a/apps/meteor/app/threads/server/functions.ts b/apps/meteor/app/threads/server/functions.ts index e79eb72ba0c58..b146cb7d00414 100644 --- a/apps/meteor/app/threads/server/functions.ts +++ b/apps/meteor/app/threads/server/functions.ts @@ -1,6 +1,6 @@ import type { IMessage } from '@rocket.chat/core-typings'; import { isEditedMessage } from '@rocket.chat/core-typings'; -import { Messages, Subscriptions, ReadReceipts } from '@rocket.chat/models'; +import { Messages, Subscriptions, ReadReceipts, NotificationQueue } from '@rocket.chat/models'; import { getMentions } from '../../lib/server/lib/notifyUsersOnMessage'; @@ -58,12 +58,8 @@ export async function unfollow({ tmid, rid, uid }: { tmid: string; rid: string; await Messages.removeThreadFollowerByThreadId(tmid, uid); } -export const readThread = async ({ userId, rid, tmid }: { userId?: string; rid: string; tmid: string }) => { +export const readThread = async ({ userId, rid, tmid }: { userId: string; rid: string; tmid: string }) => { const projection = { tunread: 1 }; - if (!userId) { - return; - } - const sub = await Subscriptions.findOneByRoomIdAndUserId(rid, userId, { projection }); if (!sub) { return; @@ -72,4 +68,5 @@ export const readThread = async ({ userId, rid, tmid }: { userId?: string; rid: const clearAlert = sub.tunread && sub.tunread?.length <= 1 && sub.tunread.includes(tmid); await Subscriptions.removeUnreadThreadByRoomIdAndUserId(rid, userId, tmid, clearAlert); + await NotificationQueue.clearQueueByUserId(userId); }; diff --git a/apps/meteor/server/methods/readThreads.ts b/apps/meteor/server/methods/readThreads.ts index d0fc7ee338148..234d0181294c5 100644 --- a/apps/meteor/server/methods/readThreads.ts +++ b/apps/meteor/server/methods/readThreads.ts @@ -43,8 +43,8 @@ Meteor.methods({ } await callbacks.run('beforeReadMessages', thread.rid, user?._id); - await readThread({ userId: user?._id, rid: thread.rid, tmid }); if (user?._id) { + await readThread({ userId: user._id, rid: thread.rid, tmid }); callbacks.runAsync('afterReadMessages', room._id, { uid: user._id, tmid }); } },