diff --git a/src/stores/room-list-v3/RoomListStoreV3.ts b/src/stores/room-list-v3/RoomListStoreV3.ts index e613f15959..92de63285e 100644 --- a/src/stores/room-list-v3/RoomListStoreV3.ts +++ b/src/stores/room-list-v3/RoomListStoreV3.ts @@ -321,8 +321,17 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient { */ private addRoomAndEmit(room: Room, isNewRoom = false): void { if (!this.roomSkipList) throw new Error("roomSkipList hasn't been created yet!"); - if (isNewRoom) this.roomSkipList.addNewRoom(room); - else this.roomSkipList.reInsertRoom(room); + if (isNewRoom) { + if (!VisibilityProvider.instance.isRoomVisible(room)) { + logger.info( + `RoomListStoreV3: Refusing to add new room ${room.roomId} because isRoomVisible returned false.`, + ); + return; + } + this.roomSkipList.addNewRoom(room); + } else { + this.roomSkipList.reInsertRoom(room); + } this.emit(LISTS_UPDATE_EVENT); } diff --git a/test/unit-tests/stores/room-list-v3/RoomListStoreV3-test.ts b/test/unit-tests/stores/room-list-v3/RoomListStoreV3-test.ts index 0f6c4203e6..0c0cdfc091 100644 --- a/test/unit-tests/stores/room-list-v3/RoomListStoreV3-test.ts +++ b/test/unit-tests/stores/room-list-v3/RoomListStoreV3-test.ts @@ -416,6 +416,32 @@ describe("RoomListStoreV3", () => { } describe("Spaces", () => { + it("Newly created space is not added by the store", async () => { + const { client, rooms } = getClientAndRooms(); + const infoSpy = jest.spyOn(logger, "info"); + + const store = new RoomListStoreV3Class(dispatcher); + await store.start(); + + // Create a space and let the store know about it + const { spaceRoom } = createSpace(rooms, [6, 8, 13, 27, 75], client); + dispatcher.dispatch( + { + action: "MatrixActions.Room.myMembership", + oldMembership: KnownMembership.Leave, + membership: KnownMembership.Invite, + room: spaceRoom, + }, + true, + ); + + // Space room should not be added + expect(store.getSortedRooms()).not.toContain(spaceRoom); + expect(infoSpy).toHaveBeenCalledWith( + expect.stringContaining("RoomListStoreV3: Refusing to add new room"), + ); + }); + it("Filtering by spaces work", async () => { const { client, rooms } = getClientAndRooms(); // Let's choose 5 rooms to put in space