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

Commit 8166306

Browse files
authored
Fix clicking on home all rooms space notification not working (#11337)
* Fix clicking on home all rooms space notification not working * Add test
1 parent e6bf67a commit 8166306

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

src/stores/spaces/SpaceStore.ts

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,35 +193,32 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
193193
if (!isMetaSpace(space) && !this.matrixClient?.getRoom(space)?.isSpaceRoom()) return;
194194
if (space !== this.activeSpace) this.setActiveSpace(space, false);
195195

196-
if (space) {
197-
const roomId = this.getNotificationState(space).getFirstRoomWithNotifications();
196+
let roomId: string | undefined;
197+
if (space === MetaSpace.Home && this.allRoomsInHome) {
198+
const hasMentions = RoomNotificationStateStore.instance.globalState.hasMentions;
199+
const lists = RoomListStore.instance.orderedLists;
200+
tagLoop: for (let i = 0; i < TAG_ORDER.length; i++) {
201+
const t = TAG_ORDER[i];
202+
if (!lists[t]) continue;
203+
for (const room of lists[t]) {
204+
const state = RoomNotificationStateStore.instance.getRoomState(room);
205+
if (hasMentions ? state.hasMentions : state.isUnread) {
206+
roomId = room.roomId;
207+
break tagLoop;
208+
}
209+
}
210+
}
211+
} else {
212+
roomId = this.getNotificationState(space).getFirstRoomWithNotifications();
213+
}
214+
215+
if (!!roomId) {
198216
defaultDispatcher.dispatch<ViewRoomPayload>({
199217
action: Action.ViewRoom,
200218
room_id: roomId,
201219
context_switch: true,
202220
metricsTrigger: "WebSpacePanelNotificationBadge",
203221
});
204-
} else {
205-
const lists = RoomListStore.instance.orderedLists;
206-
for (let i = 0; i < TAG_ORDER.length; i++) {
207-
const t = TAG_ORDER[i];
208-
const listRooms = lists[t];
209-
const unreadRoom = listRooms.find((r: Room) => {
210-
if (this.showInHomeSpace(r)) {
211-
const state = RoomNotificationStateStore.instance.getRoomState(r);
212-
return state.isUnread;
213-
}
214-
});
215-
if (unreadRoom) {
216-
defaultDispatcher.dispatch<ViewRoomPayload>({
217-
action: Action.ViewRoom,
218-
room_id: unreadRoom.roomId,
219-
context_switch: true,
220-
metricsTrigger: "WebSpacePanelNotificationBadge",
221-
});
222-
break;
223-
}
224-
}
225222
}
226223
}
227224

test/stores/SpaceStore-test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { EventType } from "matrix-js-sdk/src/@types/event";
2020
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
2121
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
2222
import { defer } from "matrix-js-sdk/src/utils";
23-
import { ClientEvent, RoomEvent, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
23+
import { ClientEvent, MatrixEvent, Room, RoomEvent } from "matrix-js-sdk/src/matrix";
2424

2525
import SpaceStore from "../../src/stores/spaces/SpaceStore";
2626
import {
@@ -38,6 +38,10 @@ import SettingsStore from "../../src/settings/SettingsStore";
3838
import { SettingLevel } from "../../src/settings/SettingLevel";
3939
import { Action } from "../../src/dispatcher/actions";
4040
import { MatrixClientPeg } from "../../src/MatrixClientPeg";
41+
import RoomListStore from "../../src/stores/room-list/RoomListStore";
42+
import { DefaultTagID } from "../../src/stores/room-list/models";
43+
import { RoomNotificationStateStore } from "../../src/stores/notifications/RoomNotificationStateStore";
44+
import { NotificationColor } from "../../src/stores/notifications/NotificationColor";
4145

4246
jest.useFakeTimers();
4347

@@ -1452,4 +1456,29 @@ describe("SpaceStore", () => {
14521456
expect(client.getVisibleRooms).not.toHaveBeenCalledWith();
14531457
});
14541458
});
1459+
1460+
describe("setActiveRoomInSpace", () => {
1461+
it("should work with Home as all rooms space", async () => {
1462+
const room = mkRoom(room1);
1463+
const state = RoomNotificationStateStore.instance.getRoomState(room);
1464+
// @ts-ignore
1465+
state._color = NotificationColor.Grey;
1466+
jest.spyOn(RoomListStore.instance, "orderedLists", "get").mockReturnValue({
1467+
[DefaultTagID.Untagged]: [room],
1468+
});
1469+
1470+
// init the store
1471+
await run();
1472+
await setShowAllRooms(true);
1473+
1474+
store.setActiveRoomInSpace(MetaSpace.Home);
1475+
1476+
expect(spyDispatcher).toHaveBeenCalledWith(
1477+
expect.objectContaining({
1478+
action: "view_room",
1479+
room_id: room.roomId,
1480+
}),
1481+
);
1482+
});
1483+
});
14551484
});

0 commit comments

Comments
 (0)