From cb6c1415804a50bbdb34c75444ef9f51994834c7 Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Mon, 27 Apr 2026 11:32:05 +0200 Subject: [PATCH] feat: exclude default section from room list item menu (#33278) --- .../room-list/RoomListItemViewModel.ts | 7 +++++-- .../room-list/RoomListItemViewModel-test.tsx | 16 ++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/apps/web/src/viewmodels/room-list/RoomListItemViewModel.ts b/apps/web/src/viewmodels/room-list/RoomListItemViewModel.ts index 68f84c7925..b247ade51c 100644 --- a/apps/web/src/viewmodels/room-list/RoomListItemViewModel.ts +++ b/apps/web/src/viewmodels/room-list/RoomListItemViewModel.ts @@ -427,8 +427,11 @@ export class RoomListItemViewModel return ( RoomListStoreV3.instance.orderedSectionTags - // Exclude the Chats section because the user toggle the other sections to move rooms in and out of the Chats section. - .filter((tag) => tag !== CHATS_TAG) + // Exclude the Chats because the user toggle the other sections to move rooms in and out of the Chats section. + // Also exclude the default sections because they are available as toggles in the main context menu, and we don't want them to be duplicated in the "Move to section" submenu. + .filter( + (tag) => tag !== CHATS_TAG && tag !== DefaultTagID.Favourite && tag !== DefaultTagID.LowPriority, + ) .map((tag) => ({ tag, name: RoomListItemViewModel.getSectionName(tag, customSectionData), diff --git a/apps/web/test/viewmodels/room-list/RoomListItemViewModel-test.tsx b/apps/web/test/viewmodels/room-list/RoomListItemViewModel-test.tsx index 53cf2f7d82..10c7d66855 100644 --- a/apps/web/test/viewmodels/room-list/RoomListItemViewModel-test.tsx +++ b/apps/web/test/viewmodels/room-list/RoomListItemViewModel-test.tsx @@ -627,7 +627,7 @@ describe("RoomListItemViewModel", () => { ]); }); - it("should include sections from orderedSectionTags excluding CHATS_TAG", () => { + it("should include sections from orderedSectionTags excluding CHATS_TAG, favourite, and low priority", () => { jest.spyOn(SettingsStore, "getValue").mockImplementation((setting) => { if (setting === "feature_room_list_sections") return true; return false; @@ -635,11 +635,11 @@ describe("RoomListItemViewModel", () => { viewModel = new RoomListItemViewModel({ room, client: matrixClient }); const sections = viewModel.getSnapshot().sections; - expect(sections.map((s) => s.tag)).toEqual([DefaultTagID.Favourite, customTag, DefaultTagID.LowPriority]); + expect(sections.map((s) => s.tag)).toEqual([customTag]); }); it("should mark the room current section as selected", () => { - room.tags = { [DefaultTagID.Favourite]: { order: 0 } }; + room.tags = { [customTag]: { order: 0 } }; jest.spyOn(SettingsStore, "getValue").mockImplementation((setting) => { if (setting === "feature_room_list_sections") return true; return false; @@ -647,8 +647,7 @@ describe("RoomListItemViewModel", () => { viewModel = new RoomListItemViewModel({ room, client: matrixClient }); const sections = viewModel.getSnapshot().sections; - expect(sections.find((s) => s.tag === DefaultTagID.Favourite)?.isSelected).toBe(true); - expect(sections.find((s) => s.tag === DefaultTagID.LowPriority)?.isSelected).toBe(false); + expect(sections.find((s) => s.tag === customTag)?.isSelected).toBe(true); }); it("should use custom section name from CustomSectionData", () => { @@ -676,7 +675,7 @@ describe("RoomListItemViewModel", () => { }); viewModel = new RoomListItemViewModel({ room, client: matrixClient }); - expect(viewModel.getSnapshot().sections).toHaveLength(3); // Favourite, custom, LowPriority + expect(viewModel.getSnapshot().sections).toHaveLength(1); // Simulate reordering: custom section removed jest.spyOn(RoomListStoreV3.instance, "orderedSectionTags", "get").mockReturnValue([ @@ -686,10 +685,7 @@ describe("RoomListItemViewModel", () => { ]); watchCallback("RoomList.OrderedCustomSections", null, null as any, null, null); - expect(viewModel.getSnapshot().sections.map((s) => s.tag)).toEqual([ - DefaultTagID.Favourite, - DefaultTagID.LowPriority, - ]); + expect(viewModel.getSnapshot().sections.map((s) => s.tag)).toEqual([]); }); });