New Room List: Prevent old tombstoned rooms from appearing in the list (#29881)

* Write failing playwright test

Basically when someone changes their name, any old tombstoned rooms that
were previously hidden would suddenly show up in the list.

* Split addRoom into two methods

- `reInsertRoom` that re-inserts a room that is already known by the skiplist.
- `addNewRoom` to add new rooms

The idea is that sometimes you only want to re-insert to noop, eg: when
you get an event in an old room that was upgraded.

* Use new methods in the RLS

Only use `addNewRoom` when absolutely necessary. Most events should
instead use `reInsertRoom` which will noop when the room isn't already
known by the skiplist.

* Fix broken tests

* Add new test

* Fix playwright test
This commit is contained in:
R Midhun Suresh
2025-05-06 21:27:13 +05:30
committed by GitHub
parent 8ac2f60720
commit 6ba21dafa7
5 changed files with 143 additions and 39 deletions
@@ -62,7 +62,7 @@ describe("RoomSkipList", () => {
for (const room of toInsert) {
// Insert this room 10 times
for (let i = 0; i < 10; ++i) {
skipList.addRoom(room);
skipList.reInsertRoom(room);
}
}
// Sorting order should be the same as before
@@ -84,7 +84,7 @@ describe("RoomSkipList", () => {
event: true,
});
room.timeline.push(event);
skipList.addRoom(room);
skipList.reInsertRoom(room);
expect(skipList.size).toEqual(rooms.length);
}
const sortedRooms = [...skipList];
@@ -93,6 +93,12 @@ describe("RoomSkipList", () => {
}
});
it("Throws error when same room is added via addNewRoom", () => {
const { skipList, rooms } = generateSkipList();
const room = rooms[5];
expect(() => skipList.addNewRoom(room)).toThrow("Can't add room to skiplist");
});
it("Re-sort works when sorter is swapped", () => {
const { skipList, rooms, sorter } = generateSkipList();
const sortedByRecency = [...rooms].sort((a, b) => sorter.comparator(a, b));
@@ -120,7 +126,7 @@ describe("RoomSkipList", () => {
// Shuffle and insert the rooms
for (const room of shuffle(rooms)) {
roomSkipList.addRoom(room);
roomSkipList.addNewRoom(room);
}
expect(roomSkipList.size).toEqual(totalRooms);