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

Add labs flag for Threads Activity Centre #12137

Merged
merged 19 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Settings isn't very performant, could we pass this value in and only read it periodically? I presume this method is called significantly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... kinda. I'm considering whether it would be simpler to memoise settings getters...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done

? 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")) {
dbkr marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@
"group_rooms": "Rooms",
"group_spaces": "Spaces",
"group_themes": "Themes",
"group_threads": "Threads",
"group_voip": "Voice & Video",
"group_widgets": "Widgets",
"hidebold": "Hide notification dot (only display counters badges)",
Expand Down Expand Up @@ -1462,6 +1463,7 @@
"sliding_sync_server_no_support": "Your server lacks native support",
"sliding_sync_server_specify_proxy": "Your server lacks native support, you must specify a proxy",
"sliding_sync_server_support": "Your server has native support",
"threads_activity_centre": "Threads Activity Centre (in development). Currently this just removes thread notification counts from the count total in the room list",
"under_active_development": "Under active development.",
"unrealiable_e2e": "Unreliable in encrypted rooms",
"video_rooms": "Video rooms",
Expand Down
10 changes: 10 additions & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export enum LabGroup {
Spaces,
Widgets,
Rooms,
Threads,
VoiceAndVideo,
Moderation,
Analytics,
Expand All @@ -104,6 +105,7 @@ export const labGroupNames: Record<LabGroup, TranslationKey> = {
[LabGroup.Spaces]: _td("labs|group_spaces"),
[LabGroup.Widgets]: _td("labs|group_widgets"),
[LabGroup.Rooms]: _td("labs|group_rooms"),
[LabGroup.Threads]: _td("labs|group_threads"),
[LabGroup.VoiceAndVideo]: _td("labs|group_voip"),
[LabGroup.Moderation]: _td("labs|group_moderation"),
[LabGroup.Analytics]: _td("common|analytics"),
Expand Down Expand Up @@ -1113,6 +1115,14 @@ export const SETTINGS: { [setting: string]: ISetting } = {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
default: [],
},
"threadsActivityCentre": {
supportedLevels: LEVELS_ACCOUNT_SETTINGS,
labsGroup: LabGroup.Threads,
controller: new ReloadOnChangeController(),
displayName: _td("labs|threads_activity_centre"),
default: false,
isFeature: true,
},
[UIFeature.RoomHistorySettings]: {
supportedLevels: LEVELS_UI_FEATURE,
default: 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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe("<LabsUserSettingsTab />", () => {
// non-beta labs section
expect(screen.getByText("Early previews")).toBeInTheDocument();
const labsSections = container.getElementsByClassName("mx_SettingsSubsection");
expect(labsSections).toHaveLength(9);
expect(labsSections).toHaveLength(10);
});

describe("Rust crypto setting", () => {
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;
}
});
Loading