From a3a387a1dd8fa7b4972ac032a5b3c6db2161f110 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Wed, 31 Jan 2024 17:24:56 +0100 Subject: [PATCH] Fix default thread notification of the new RoomHeader (#12194) --- 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 374301d137..944920d87c 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 ee0afee8ca..8946a1f2ec 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,