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

Commit

Permalink
Merge pull request #12156 from matrix-org/dbkr/split_unread_counts
Browse files Browse the repository at this point in the history
Make threads activity centre labs flag split out unread counts
  • Loading branch information
dbkr authored Jan 23, 2024
2 parents 3734924 + f2dc6f9 commit 1e4b378
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/RoomNotifs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/Unread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export function doesRoomHaveUnreadMessages(room: Room): boolean {
return false;
}

for (const withTimeline of [room, ...room.getThreads()]) {
const toCheck: Array<Room | Thread> = [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;
Expand Down
1 change: 1 addition & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions test/components/views/rooms/LegacyRoomHeader-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,11 @@ 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 {
return undefined;
}
};
}

Expand Down
1 change: 1 addition & 0 deletions test/stores/RoomNotificationStateStore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});

0 comments on commit 1e4b378

Please sign in to comment.