Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 4 additions & 2 deletions apps/meteor/client/lib/chats/readStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class ReadStateManager extends Emitter {
return this.firstUnreadRecordId;
};

public subscribeToMessages() {
return RoomHistoryManager.on('loaded-messages', () => this.updateFirstUnreadRecordId());
}

public updateSubscription(subscription?: ISubscription) {
if (!subscription) {
return;
Expand Down Expand Up @@ -88,8 +92,6 @@ export class ReadStateManager extends Emitter {
);

this.setFirstUnreadRecordId(firstUnreadRecord?._id);

RoomHistoryManager.once('loaded-messages', () => this.updateFirstUnreadRecordId());
}

private setFirstUnreadRecordId(firstUnreadRecordId: string | undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jest.mock('../../../../../app/ui/client/lib/ChatMessages', () => {
release: jest.fn(),
readStateManager: {
updateSubscription: updateSubscriptionMock,
subscribeToMessages: jest.fn(),
},
};
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export function useChatMessagesInstance({
return [instance, () => instance.release()];
}, [rid, tmid, uid, encrypted, e2eRoomState]);

useEffect(() => {
if (subscription?.rid) {
return chatMessages?.readStateManager.subscribeToMessages();
}
}, [subscription?.rid, chatMessages?.readStateManager]);

useEffect(() => {
if (subscription) {
chatMessages?.readStateManager.updateSubscription(subscription);
Expand Down
Loading