Skip to content

Commit

Permalink
Fix read receipts not being created on the first time a user reads a …
Browse files Browse the repository at this point in the history
…room
  • Loading branch information
matheusbsilva137 committed Oct 9, 2023
1 parent 1814410 commit 968de5a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ callbacks.add(

if (tmid) {
await MessageReads.readThread(uid, tmid);
} else if (lastSeen) {
} else {
await ReadReceipt.markMessagesAsRead(rid, uid, lastSeen);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/models/raw/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ export class MessagesRaw extends BaseRaw<IMessage> implements IMessagesModel {
);
}

findVisibleUnreadMessagesByRoomAndDate(rid: string, after: Date): FindCursor<Pick<IMessage, '_id' | 't' | 'pinned' | 'drid' | 'tmid'>> {
findVisibleUnreadMessagesByRoomAndDate(rid: string, after?: Date): FindCursor<Pick<IMessage, '_id' | 't' | 'pinned' | 'drid' | 'tmid'>> {
const query = {
unread: true,
rid,
Expand Down
2 changes: 1 addition & 1 deletion packages/model-typings/src/models/IMessagesModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export interface IMessagesModel extends IBaseModel<IMessage> {
userId: string,
after: Date,
): FindCursor<Pick<IMessage, '_id' | 't' | 'pinned' | 'drid' | 'tmid'>>;
findVisibleUnreadMessagesByRoomAndDate(rid: string, after: Date): FindCursor<Pick<IMessage, '_id' | 't' | 'pinned' | 'drid' | 'tmid'>>;
findVisibleUnreadMessagesByRoomAndDate(rid: string, after?: Date): FindCursor<Pick<IMessage, '_id' | 't' | 'pinned' | 'drid' | 'tmid'>>;
setAsReadById(_id: string): Promise<UpdateResult>;
countThreads(): Promise<number>;
addThreadFollowerByThreadId(tmid: string, userId: string): Promise<UpdateResult>;
Expand Down

0 comments on commit 968de5a

Please sign in to comment.