From 968de5a987de09c6d6c34d1b4fe3fe079e94c2a3 Mon Sep 17 00:00:00 2001 From: matheusbsilva137 Date: Mon, 9 Oct 2023 19:34:57 -0300 Subject: [PATCH] Fix read receipts not being created on the first time a user reads a room --- .../app/message-read-receipt/server/hooks/afterReadMessages.ts | 2 +- apps/meteor/ee/server/lib/message-read-receipt/ReadReceipt.js | 2 +- apps/meteor/server/models/raw/Messages.ts | 2 +- packages/model-typings/src/models/IMessagesModel.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/meteor/ee/app/message-read-receipt/server/hooks/afterReadMessages.ts b/apps/meteor/ee/app/message-read-receipt/server/hooks/afterReadMessages.ts index f96a9a773fec..293ab0a17373 100644 --- a/apps/meteor/ee/app/message-read-receipt/server/hooks/afterReadMessages.ts +++ b/apps/meteor/ee/app/message-read-receipt/server/hooks/afterReadMessages.ts @@ -15,7 +15,7 @@ callbacks.add( if (tmid) { await MessageReads.readThread(uid, tmid); - } else if (lastSeen) { + } else { await ReadReceipt.markMessagesAsRead(rid, uid, lastSeen); } }, diff --git a/apps/meteor/ee/server/lib/message-read-receipt/ReadReceipt.js b/apps/meteor/ee/server/lib/message-read-receipt/ReadReceipt.js index bb957b8f2b14..710c1a10d451 100644 --- a/apps/meteor/ee/server/lib/message-read-receipt/ReadReceipt.js +++ b/apps/meteor/ee/server/lib/message-read-receipt/ReadReceipt.js @@ -40,7 +40,7 @@ export const ReadReceipt = { const room = await Rooms.findOneById(roomId, { projection: { lm: 1 } }); // if users last seen is greater than room's last message, it means the user already have this room marked as read - if (!room || userLastSeen > room.lm) { + if (!room || (userLastSeen && userLastSeen > room.lm)) { return; } diff --git a/apps/meteor/server/models/raw/Messages.ts b/apps/meteor/server/models/raw/Messages.ts index 49930a8c92ea..8f35e5efe020 100644 --- a/apps/meteor/server/models/raw/Messages.ts +++ b/apps/meteor/server/models/raw/Messages.ts @@ -1536,7 +1536,7 @@ export class MessagesRaw extends BaseRaw implements IMessagesModel { ); } - findVisibleUnreadMessagesByRoomAndDate(rid: string, after: Date): FindCursor> { + findVisibleUnreadMessagesByRoomAndDate(rid: string, after?: Date): FindCursor> { const query = { unread: true, rid, diff --git a/packages/model-typings/src/models/IMessagesModel.ts b/packages/model-typings/src/models/IMessagesModel.ts index d681405850fa..99d0a9a0e380 100644 --- a/packages/model-typings/src/models/IMessagesModel.ts +++ b/packages/model-typings/src/models/IMessagesModel.ts @@ -258,7 +258,7 @@ export interface IMessagesModel extends IBaseModel { userId: string, after: Date, ): FindCursor>; - findVisibleUnreadMessagesByRoomAndDate(rid: string, after: Date): FindCursor>; + findVisibleUnreadMessagesByRoomAndDate(rid: string, after?: Date): FindCursor>; setAsReadById(_id: string): Promise; countThreads(): Promise; addThreadFollowerByThreadId(tmid: string, userId: string): Promise;