Fix room list throwing an error when adding an existing room (#34281)
This commit is contained in:
@@ -6,6 +6,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import type { Room } from "matrix-js-sdk/src/matrix";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import type { Sorter, SortingAlgorithm } from "./sorters";
|
||||
import type { Filter, FilterKey } from "./filters";
|
||||
import { RoomNode } from "./RoomNode";
|
||||
@@ -115,12 +116,13 @@ export class RoomSkipList implements Iterable<Room> {
|
||||
|
||||
/**
|
||||
* Adds a new room to the skiplist.
|
||||
* This method will throw an error if the room is already in the skiplist.
|
||||
* This method does nothing if the room is already in the skiplist.
|
||||
* @param room the room to add
|
||||
*/
|
||||
public addNewRoom(room: Room): void {
|
||||
if (this.roomNodeMap.has(room.roomId)) {
|
||||
throw new Error(`Can't add room to skiplist: ${room.roomId} is already in the skiplist!`);
|
||||
logger.error(`Can't add room to skiplist: ${room.roomId} is already in the skiplist!`);
|
||||
return;
|
||||
}
|
||||
this.insertRoom(room);
|
||||
}
|
||||
|
||||
@@ -100,10 +100,13 @@ describe("RoomSkipList", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("Throws error when same room is added via addNewRoom", () => {
|
||||
it("Room is not duplicated 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");
|
||||
const sizeBefore = skipList.size;
|
||||
skipList.addNewRoom(room);
|
||||
|
||||
expect(skipList.size).toEqual(sizeBefore);
|
||||
});
|
||||
|
||||
it("Filters are applied to existing nodes when useNewFilters is called", () => {
|
||||
|
||||
Reference in New Issue
Block a user