From ec35d7c182499cf6c2c52094a789955caa17ae37 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Wed, 31 Jan 2024 11:01:43 +0100 Subject: [PATCH] Fix default thread notification of the new RoomHeader --- src/hooks/room/useRoomThreadNotifications.ts | 5 ++++- test/hooks/room/useRoomThreadNotifications-test.tsx | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hooks/room/useRoomThreadNotifications.ts b/src/hooks/room/useRoomThreadNotifications.ts index 374301d1371..944920d87c0 100644 --- a/src/hooks/room/useRoomThreadNotifications.ts +++ b/src/hooks/room/useRoomThreadNotifications.ts @@ -44,9 +44,12 @@ export const useRoomThreadNotifications = (room: Room): NotificationLevel => { // If the current thread has unread messages, we're done. if (doesRoomOrThreadHaveUnreadMessages(thread)) { setNotificationLevel(NotificationLevel.Activity); - break; + return; } } + + // default case + setNotificationLevel(NotificationLevel.None); }, [room]); useEventEmitter(room, RoomEvent.UnreadNotifications, updateNotification); diff --git a/test/hooks/room/useRoomThreadNotifications-test.tsx b/test/hooks/room/useRoomThreadNotifications-test.tsx index ee0afee8cae..8946a1f2ec4 100644 --- a/test/hooks/room/useRoomThreadNotifications-test.tsx +++ b/test/hooks/room/useRoomThreadNotifications-test.tsx @@ -44,6 +44,13 @@ describe("useRoomThreadNotifications", () => { expect(result.current).toBe(NotificationLevel.None); }); + it("returns none if the thread hasn't a notification anymore", async () => { + room.setThreadUnreadNotificationCount("flooble", NotificationCountType.Highlight, 0); + const { result } = render(room); + + expect(result.current).toBe(NotificationLevel.None); + }); + it("returns red if a thread in the room has a highlight notification", async () => { room.setThreadUnreadNotificationCount("flooble", NotificationCountType.Highlight, 1); const { result } = render(room); @@ -58,7 +65,7 @@ describe("useRoomThreadNotifications", () => { expect(result.current).toBe(NotificationLevel.Notification); }); - it("returns bold if a thread in the room unread messages", async () => { + it("returns activity if a thread in the room unread messages", async () => { await populateThread({ room, client: cli,