Skip to content

Commit

Permalink
Mark as read only messages sent after subscription's creation
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 committed Oct 10, 2023
1 parent 31584ca commit 7257ce2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 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 {
} else if (lastSeen) {
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 && userLastSeen > room.lm)) {
if (!room || userLastSeen > room.lm) {
return;
}

Expand Down
5 changes: 3 additions & 2 deletions apps/meteor/server/lib/readMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { callbacks } from '../../lib/callbacks';
export async function readMessages(rid: IRoom['_id'], uid: IUser['_id'], readThreads: boolean): Promise<void> {
await callbacks.run('beforeReadMessages', rid, uid);

const projection = { ls: 1, tunread: 1, alert: 1 };
const projection = { ls: 1, tunread: 1, alert: 1, _updatedAt: 1 };
const sub = await Subscriptions.findOneByRoomIdAndUserId(rid, uid, { projection });
if (!sub) {
throw new Error('error-invalid-subscription');
Expand All @@ -19,5 +19,6 @@ export async function readMessages(rid: IRoom['_id'], uid: IUser['_id'], readThr

await NotificationQueue.clearQueueByUserId(uid);

callbacks.runAsync('afterReadMessages', rid, { uid, lastSeen: sub.ls });
const lastSeen = sub.ls || sub._updatedAt;
callbacks.runAsync('afterReadMessages', rid, { uid, lastSeen });
}
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

0 comments on commit 7257ce2

Please sign in to comment.