fix: Notifications for thread messages are sent even after thread has been read (#31181)

pull/31217/head^2
Matheus Barbosa Silva 2 years ago committed by GitHub
parent 1bcb57cd40
commit fae558bd5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .changeset/calm-rules-dance.md
  2. 9
      apps/meteor/app/threads/server/functions.ts
  3. 2
      apps/meteor/server/methods/readThreads.ts

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

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

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

Loading…
Cancel
Save