Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit UnreadNotification event on notifications reset #2804

Merged
merged 2 commits into from
Oct 26, 2022
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
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