From 5b854dcc6a7aacecb03b706a1e93ea134004329d Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 18 Jan 2024 16:43:24 +0000 Subject: [PATCH 1/3] Make threads activity centre labs flag split out unread counts Just shows notif & unread counts for main thread if the TAC is enabled. --- src/RoomNotifs.ts | 9 ++++++--- src/Unread.ts | 7 ++++++- src/settings/Settings.tsx | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/RoomNotifs.ts b/src/RoomNotifs.ts index aa696f6e29c..1380f4abddd 100644 --- a/src/RoomNotifs.ts +++ b/src/RoomNotifs.ts @@ -81,9 +81,12 @@ export function setRoomNotifsState(client: MatrixClient, roomId: string, newStat } export function getUnreadNotificationCount(room: Room, type: NotificationCountType, threadId?: string): number { - let notificationCount = !!threadId - ? room.getThreadUnreadNotificationCount(threadId, type) - : room.getUnreadNotificationCount(type); + const countShownForRoom = (): number => + SettingsStore.getValue("threadsActivityCentre") + ? room.getRoomUnreadNotificationCount(type) + : room.getUnreadNotificationCount(type); + + let notificationCount = !!threadId ? room.getThreadUnreadNotificationCount(threadId, type) : countShownForRoom(); // Check notification counts in the old room just in case there's some lost // there. We only go one level down to avoid performance issues, and theory diff --git a/src/Unread.ts b/src/Unread.ts index 7b2da855dd7..daf6bc54551 100644 --- a/src/Unread.ts +++ b/src/Unread.ts @@ -57,7 +57,12 @@ export function doesRoomHaveUnreadMessages(room: Room): boolean { return false; } - for (const withTimeline of [room, ...room.getThreads()]) { + const toCheck: Array = [room]; + if (!SettingsStore.getValue("threadsActivityCentre")) { + toCheck.push(...room.getThreads()); + } + + for (const withTimeline of toCheck) { if (doesTimelineHaveUnreadMessages(room, withTimeline.timeline)) { // We found an unread, so the room is unread return true; diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 202d3498c6d..84a40396faa 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -1109,6 +1109,7 @@ export const SETTINGS: { [setting: string]: ISetting } = { "threadsActivityCentre": { supportedLevels: LEVELS_ACCOUNT_SETTINGS, labsGroup: LabGroup.Threads, + controller: new ReloadOnChangeController(), displayName: _td("labs|threads_activity_centre"), default: false, isFeature: true, From ba9ad0763dc247ac3e31da5d47b1440697ea0463 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 18 Jan 2024 17:16:20 +0000 Subject: [PATCH 2/3] Fix tests --- .../views/rooms/LegacyRoomHeader-test.tsx | 13 +++++++++++-- test/stores/RoomNotificationStateStore-test.ts | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/components/views/rooms/LegacyRoomHeader-test.tsx b/test/components/views/rooms/LegacyRoomHeader-test.tsx index ed82f74630c..8e0768cec56 100644 --- a/test/components/views/rooms/LegacyRoomHeader-test.tsx +++ b/test/components/views/rooms/LegacyRoomHeader-test.tsx @@ -792,8 +792,17 @@ function createRoom(info: IRoomCreationInfo) { const userId = client.getUserId()!; if (info.isDm) { client.getAccountData = (eventType) => { - expect(eventType).toEqual("m.direct"); - return mkDirectEvent(roomId, userId, info.userIds); + if (eventType === "m.direct") { + return mkDirectEvent(roomId, userId, info.userIds); + } else if (eventType === "im.vector.web.settings") { + return mkEvent({ + event: true, + type: "im.vector.web.settings", + room: roomId, + user: userId, + content: {}, + }); + } }; } diff --git a/test/stores/RoomNotificationStateStore-test.ts b/test/stores/RoomNotificationStateStore-test.ts index acb6a593471..46b57425d6b 100644 --- a/test/stores/RoomNotificationStateStore-test.ts +++ b/test/stores/RoomNotificationStateStore-test.ts @@ -125,6 +125,7 @@ describe("RoomNotificationStateStore", function () { ret.getPendingEvents = jest.fn().mockReturnValue([]); ret.isSpaceRoom = jest.fn().mockReturnValue(false); ret.getUnreadNotificationCount = jest.fn().mockReturnValue(numUnreads); + ret.getRoomUnreadNotificationCount = jest.fn().mockReturnValue(numUnreads); return ret; } }); From f2dc6f9f15164340b203416aa494a6da62ef5a0c Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 18 Jan 2024 17:21:33 +0000 Subject: [PATCH 3/3] Simpler fix --- test/components/views/rooms/LegacyRoomHeader-test.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/test/components/views/rooms/LegacyRoomHeader-test.tsx b/test/components/views/rooms/LegacyRoomHeader-test.tsx index 8e0768cec56..7dadf14dbee 100644 --- a/test/components/views/rooms/LegacyRoomHeader-test.tsx +++ b/test/components/views/rooms/LegacyRoomHeader-test.tsx @@ -794,14 +794,8 @@ function createRoom(info: IRoomCreationInfo) { client.getAccountData = (eventType) => { if (eventType === "m.direct") { return mkDirectEvent(roomId, userId, info.userIds); - } else if (eventType === "im.vector.web.settings") { - return mkEvent({ - event: true, - type: "im.vector.web.settings", - room: roomId, - user: userId, - content: {}, - }); + } else { + return undefined; } }; }