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
This commit is contained in:
@@ -321,8 +321,17 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
|
|||||||
*/
|
*/
|
||||||
private addRoomAndEmit(room: Room, isNewRoom = false): void {
|
private addRoomAndEmit(room: Room, isNewRoom = false): void {
|
||||||
if (!this.roomSkipList) throw new Error("roomSkipList hasn't been created yet!");
|
if (!this.roomSkipList) throw new Error("roomSkipList hasn't been created yet!");
|
||||||
if (isNewRoom) this.roomSkipList.addNewRoom(room);
|
if (isNewRoom) {
|
||||||
else this.roomSkipList.reInsertRoom(room);
|
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);
|
this.emit(LISTS_UPDATE_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -416,6 +416,32 @@ describe("RoomListStoreV3", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("Spaces", () => {
|
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 () => {
|
it("Filtering by spaces work", async () => {
|
||||||
const { client, rooms } = getClientAndRooms();
|
const { client, rooms } = getClientAndRooms();
|
||||||
// Let's choose 5 rooms to put in space
|
// Let's choose 5 rooms to put in space
|
||||||
|
|||||||
Reference in New Issue
Block a user