Room list: fix expanded/collapse state of sections (#33074)

* fix: section being empty in flat list mode

When switching space (or removing a section later), if the Chat section
is collpased and the room list is in flat list mode in the other space,
the room list is empty.

The fix forces the section to be in expanded state if in flat list mode

* fix: store section expanded state by space
This commit is contained in:
Florian Duros
2026-04-08 14:44:52 +01:00
committed by GitHub
parent ce498ef983
commit 121c2d18e9
4 changed files with 106 additions and 8 deletions
@@ -30,6 +30,7 @@ describe("RoomListSectionHeaderViewModel", () => {
const vm = new RoomListSectionHeaderViewModel({
tag: "m.favourite",
title: "Favourites",
spaceId: "!space:server",
onToggleExpanded,
});
@@ -43,6 +44,7 @@ describe("RoomListSectionHeaderViewModel", () => {
const vm = new RoomListSectionHeaderViewModel({
tag: "m.favourite",
title: "Favourites",
spaceId: "!space:server",
onToggleExpanded,
});
expect(vm.isExpanded).toBe(true);
@@ -58,6 +60,33 @@ describe("RoomListSectionHeaderViewModel", () => {
expect(onToggleExpanded).toHaveBeenCalledWith(true);
});
it("should track expanded state per space", () => {
const vm = new RoomListSectionHeaderViewModel({
tag: "m.favourite",
title: "Favourites",
spaceId: "!space:server",
onToggleExpanded,
});
// Default space: collapse
vm.onClick();
expect(vm.isExpanded).toBe(false);
// Switch to a different space: should default to expanded
vm.setSpace("!space2:server");
expect(vm.isExpanded).toBe(true);
// Collapse in the new space
vm.onClick();
expect(vm.isExpanded).toBe(false);
vm.onClick();
expect(vm.isExpanded).toBe(true);
// Switch to the other space: should still be collapsed
vm.setSpace("!space:server");
expect(vm.isExpanded).toBe(false);
});
describe("unread status", () => {
let room: Room;
let notificationState: RoomNotificationState;
@@ -72,6 +101,7 @@ describe("RoomListSectionHeaderViewModel", () => {
const vm = new RoomListSectionHeaderViewModel({
tag: "m.favourite",
title: "Favourites",
spaceId: "!space:server",
onToggleExpanded,
});
vm.setRooms([room]);
@@ -85,6 +115,7 @@ describe("RoomListSectionHeaderViewModel", () => {
const vm = new RoomListSectionHeaderViewModel({
tag: "m.favourite",
title: "Favourites",
spaceId: "!space:server",
onToggleExpanded,
});
vm.setRooms([room]);
@@ -107,6 +138,7 @@ describe("RoomListSectionHeaderViewModel", () => {
const vm = new RoomListSectionHeaderViewModel({
tag: "m.favourite",
title: "Favourites",
spaceId: "!space:server",
onToggleExpanded,
});
vm.setRooms([room]);
@@ -127,6 +159,7 @@ describe("RoomListSectionHeaderViewModel", () => {
const vm = new RoomListSectionHeaderViewModel({
tag: "m.favourite",
title: "Favourites",
spaceId: "!space:server",
onToggleExpanded,
});
vm.setRooms([room]);
@@ -145,6 +178,7 @@ describe("RoomListSectionHeaderViewModel", () => {
const vm = new RoomListSectionHeaderViewModel({
tag: "m.favourite",
title: "Favourites",
spaceId: "!space:server",
onToggleExpanded,
});
vm.setRooms([room]);
@@ -806,10 +806,10 @@ describe("RoomListViewModel", () => {
expect(favSection!.roomIds).toEqual([]);
});
it("should preserve section collapse state across space changes", () => {
it("should track section collapse state per space", () => {
viewModel = new RoomListViewModel({ client: matrixClient });
// Collapse favourites
// Collapse favourites in the home space
const favHeader = viewModel.getSectionHeaderViewModel(DefaultTagID.Favourite);
favHeader.onClick();
@@ -828,15 +828,37 @@ describe("RoomListViewModel", () => {
RoomListStoreV3.instance.emit(RoomListStoreV3Event.ListsUpdate);
const snapshot = viewModel.getSnapshot();
// Favourites should still be collapsed even after the space change
const favSection = snapshot.sections.find((s) => s.id === DefaultTagID.Favourite);
let snapshot = viewModel.getSnapshot();
// Favourites should be expanded in the new space (per-space state)
let favSection = snapshot.sections.find((s) => s.id === DefaultTagID.Favourite);
expect(favSection).toBeDefined();
expect(favSection!.roomIds).toEqual(["!spacefav:server"]);
// Other sections should also be expanded
let chatsSection = snapshot.sections.find((s) => s.id === CHATS_TAG);
expect(chatsSection!.roomIds).toEqual(["!spacereg:server"]);
// Switch back to home space
jest.spyOn(RoomListStoreV3.instance, "getSortedRoomsInActiveSpace").mockReturnValue({
spaceId: "home",
sections: [
{ tag: DefaultTagID.Favourite, rooms: [favRoom1, favRoom2] },
{ tag: CHATS_TAG, rooms: [regularRoom1] },
{ tag: DefaultTagID.LowPriority, rooms: [] },
],
});
RoomListStoreV3.instance.emit(RoomListStoreV3Event.ListsUpdate);
snapshot = viewModel.getSnapshot();
// Favourites should still be collapsed in the home space
favSection = snapshot.sections.find((s) => s.id === DefaultTagID.Favourite);
expect(favSection).toBeDefined();
expect(favSection!.roomIds).toEqual([]);
// Other sections should remain expanded
const chatsSection = snapshot.sections.find((s) => s.id === CHATS_TAG);
expect(chatsSection!.roomIds).toEqual(["!spacereg:server"]);
// Chats should be expanded
chatsSection = snapshot.sections.find((s) => s.id === CHATS_TAG);
expect(chatsSection!.roomIds).toEqual(["!reg1:server"]);
});
it("should apply filters across all sections", () => {