Skip to content

Commit 78ec757

Browse files
RoomListStoreV3: Only add new rooms that pass VisibilityProvider check (#29974)
* Add new rooms only after checking VisibilityProvider Otherwise we might end up adding space rooms and other rooms that must be hidden. * Write test
1 parent 45f41a3 commit 78ec757

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/stores/room-list-v3/RoomListStoreV3.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,17 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
321321
*/
322322
private addRoomAndEmit(room: Room, isNewRoom = false): void {
323323
if (!this.roomSkipList) throw new Error("roomSkipList hasn't been created yet!");
324-
if (isNewRoom) this.roomSkipList.addNewRoom(room);
325-
else this.roomSkipList.reInsertRoom(room);
324+
if (isNewRoom) {
325+
if (!VisibilityProvider.instance.isRoomVisible(room)) {
326+
logger.info(
327+
`RoomListStoreV3: Refusing to add new room ${room.roomId} because isRoomVisible returned false.`,
328+
);
329+
return;
330+
}
331+
this.roomSkipList.addNewRoom(room);
332+
} else {
333+
this.roomSkipList.reInsertRoom(room);
334+
}
326335
this.emit(LISTS_UPDATE_EVENT);
327336
}
328337

test/unit-tests/stores/room-list-v3/RoomListStoreV3-test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,32 @@ describe("RoomListStoreV3", () => {
416416
}
417417

418418
describe("Spaces", () => {
419+
it("Newly created space is not added by the store", async () => {
420+
const { client, rooms } = getClientAndRooms();
421+
const infoSpy = jest.spyOn(logger, "info");
422+
423+
const store = new RoomListStoreV3Class(dispatcher);
424+
await store.start();
425+
426+
// Create a space and let the store know about it
427+
const { spaceRoom } = createSpace(rooms, [6, 8, 13, 27, 75], client);
428+
dispatcher.dispatch(
429+
{
430+
action: "MatrixActions.Room.myMembership",
431+
oldMembership: KnownMembership.Leave,
432+
membership: KnownMembership.Invite,
433+
room: spaceRoom,
434+
},
435+
true,
436+
);
437+
438+
// Space room should not be added
439+
expect(store.getSortedRooms()).not.toContain(spaceRoom);
440+
expect(infoSpy).toHaveBeenCalledWith(
441+
expect.stringContaining("RoomListStoreV3: Refusing to add new room"),
442+
);
443+
});
444+
419445
it("Filtering by spaces work", async () => {
420446
const { client, rooms } = getClientAndRooms();
421447
// Let's choose 5 rooms to put in space

0 commit comments

Comments
 (0)