From dddc0aeccb32c8efc1cbb7e7bd033c6bd251e375 Mon Sep 17 00:00:00 2001 From: Germain Date: Wed, 26 Oct 2022 14:23:54 +0100 Subject: [PATCH] Emit UnreadNotification event on notifications reset (#2804) --- spec/unit/room.spec.ts | 13 +++++++++++++ src/models/room.ts | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spec/unit/room.spec.ts b/spec/unit/room.spec.ts index 7f1c1b7db78..29a96eab6a1 100644 --- a/spec/unit/room.spec.ts +++ b/spec/unit/room.spec.ts @@ -2723,6 +2723,19 @@ describe("Room", function() { expect(room.getThreadUnreadNotificationCount("123", NotificationCountType.Total)).toBe(666); expect(room.getThreadUnreadNotificationCount("456", NotificationCountType.Highlight)).toBe(0); }); + + it("emits event on notifications reset", () => { + const cb = jest.fn(); + + room.on(RoomEvent.UnreadNotifications, cb); + + room.setThreadUnreadNotificationCount("123", NotificationCountType.Total, 666); + room.setThreadUnreadNotificationCount("456", NotificationCountType.Highlight, 123); + + room.resetThreadUnreadNotificationCount(); + + expect(cb).toHaveBeenLastCalledWith(); + }); }); describe("hasThreadUnreadNotification", () => { diff --git a/src/models/room.ts b/src/models/room.ts index 0779eea2d61..67df5816392 100644 --- a/src/models/room.ts +++ b/src/models/room.ts @@ -173,7 +173,7 @@ export type RoomEventHandlerMap = { room: Room, ) => void; [RoomEvent.UnreadNotifications]: ( - unreadNotifications: NotificationCount, + unreadNotifications?: NotificationCount, threadId?: string, ) => void; [RoomEvent.TimelineRefresh]: (room: Room, eventTimelineSet: EventTimelineSet) => void; @@ -1277,6 +1277,7 @@ export class Room extends ReadReceipt { } else { this.threadNotifications.clear(); } + this.emit(RoomEvent.UnreadNotifications); } /**