Skip to content

Commit

Permalink
Emit UnreadNotification event on notifications reset (#2804)
Browse files Browse the repository at this point in the history
  • Loading branch information
Germain authored Oct 26, 2022
1 parent 9f6b42d commit dddc0ae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions spec/unit/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
3 changes: 2 additions & 1 deletion src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1277,6 +1277,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
} else {
this.threadNotifications.clear();
}
this.emit(RoomEvent.UnreadNotifications);
}

/**
Expand Down

0 comments on commit dddc0ae

Please sign in to comment.