Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/calm-rules-dance.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 3 additions & 6 deletions apps/meteor/app/threads/server/functions.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
Expand All @@ -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);
};
2 changes: 1 addition & 1 deletion apps/meteor/server/methods/readThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Meteor.methods<ServerMethods>({
}

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 });
}
},
Expand Down