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

Make threads activity centre labs flag split out unread counts #12156

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
});