Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 1e4b378

Browse files
authored
Merge pull request #12156 from matrix-org/dbkr/split_unread_counts
Make threads activity centre labs flag split out unread counts
2 parents 3734924 + f2dc6f9 commit 1e4b378

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

src/RoomNotifs.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,12 @@ export function setRoomNotifsState(client: MatrixClient, roomId: string, newStat
8181
}
8282

8383
export function getUnreadNotificationCount(room: Room, type: NotificationCountType, threadId?: string): number {
84-
let notificationCount = !!threadId
85-
? room.getThreadUnreadNotificationCount(threadId, type)
86-
: room.getUnreadNotificationCount(type);
84+
const countShownForRoom = (): number =>
85+
SettingsStore.getValue("threadsActivityCentre")
86+
? room.getRoomUnreadNotificationCount(type)
87+
: room.getUnreadNotificationCount(type);
88+
89+
let notificationCount = !!threadId ? room.getThreadUnreadNotificationCount(threadId, type) : countShownForRoom();
8790

8891
// Check notification counts in the old room just in case there's some lost
8992
// there. We only go one level down to avoid performance issues, and theory

src/Unread.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ export function doesRoomHaveUnreadMessages(room: Room): boolean {
5757
return false;
5858
}
5959

60-
for (const withTimeline of [room, ...room.getThreads()]) {
60+
const toCheck: Array<Room | Thread> = [room];
61+
if (!SettingsStore.getValue("threadsActivityCentre")) {
62+
toCheck.push(...room.getThreads());
63+
}
64+
65+
for (const withTimeline of toCheck) {
6166
if (doesTimelineHaveUnreadMessages(room, withTimeline.timeline)) {
6267
// We found an unread, so the room is unread
6368
return true;

src/settings/Settings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@ export const SETTINGS: { [setting: string]: ISetting } = {
11091109
"threadsActivityCentre": {
11101110
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
11111111
labsGroup: LabGroup.Threads,
1112+
controller: new ReloadOnChangeController(),
11121113
displayName: _td("labs|threads_activity_centre"),
11131114
default: false,
11141115
isFeature: true,

test/components/views/rooms/LegacyRoomHeader-test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,11 @@ function createRoom(info: IRoomCreationInfo) {
792792
const userId = client.getUserId()!;
793793
if (info.isDm) {
794794
client.getAccountData = (eventType) => {
795-
expect(eventType).toEqual("m.direct");
796-
return mkDirectEvent(roomId, userId, info.userIds);
795+
if (eventType === "m.direct") {
796+
return mkDirectEvent(roomId, userId, info.userIds);
797+
} else {
798+
return undefined;
799+
}
797800
};
798801
}
799802

test/stores/RoomNotificationStateStore-test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ describe("RoomNotificationStateStore", function () {
125125
ret.getPendingEvents = jest.fn().mockReturnValue([]);
126126
ret.isSpaceRoom = jest.fn().mockReturnValue(false);
127127
ret.getUnreadNotificationCount = jest.fn().mockReturnValue(numUnreads);
128+
ret.getRoomUnreadNotificationCount = jest.fn().mockReturnValue(numUnreads);
128129
return ret;
129130
}
130131
});

0 commit comments

Comments
 (0)