feat: add in skip list a method to change filters

This commit is contained in:
Florian Duros 2026-04-15 15:38:48 +02:00
parent 68031f4246
commit b95d5f89ec
No known key found for this signature in database
GPG Key ID: A5BBB4041B493F15
2 changed files with 34 additions and 0 deletions

View File

@ -76,6 +76,17 @@ export class RoomSkipList implements Iterable<Room> {
this.seed(rooms);
}
/**
* Change the filters used by the skip list.
* This will apply the new filters to all existing nodes.
*/
public useNewFilters(filters: Filter[]): void {
this.filters = filters;
for (const node of this.roomNodeMap.values()) {
node.applyFilters(this.filters);
}
}
/**
* Removes a given room from the skip list.
*/

View File

@ -18,6 +18,9 @@ import { getMockedRooms } from "./getMockedRooms";
import SpaceStore from "../../../../../src/stores/spaces/SpaceStore";
import { MetaSpace } from "../../../../../src/stores/spaces";
import { RoomNotificationStateStore } from "../../../../../src/stores/notifications/RoomNotificationStateStore";
import { FavouriteFilter } from "../../../../../src/stores/room-list-v3/skip-list/filters/FavouriteFilter";
import { FilterEnum } from "../../../../../src/stores/room-list-v3/skip-list/filters";
import { DefaultTagID } from "../../../../../src/stores/room-list-v3/skip-list/tag";
describe("RoomSkipList", () => {
function generateSkipList(roomCount?: number): {
@ -99,6 +102,26 @@ describe("RoomSkipList", () => {
expect(() => skipList.addNewRoom(room)).toThrow("Can't add room to skiplist");
});
it("Filters are applied to existing nodes when useNewFilters is called", () => {
const { skipList, rooms } = generateSkipList(10);
// Mark some rooms as favourite
const favouriteRooms = [rooms[2], rooms[5], rooms[8]];
for (const room of favouriteRooms) {
room.tags = { [DefaultTagID.Favourite]: { order: 0 } };
}
// No filters yet — all rooms are in the list
expect(skipList.size).toEqual(10);
// Apply the favourite filter
skipList.useNewFilters([new FavouriteFilter()]);
// Only favourite rooms should be returned when filtering by favourite
const filteredRooms = Array.from(skipList.getRoomsInActiveSpace([FilterEnum.FavouriteFilter]));
expect(filteredRooms).toHaveLength(favouriteRooms.length);
});
it("Re-sort works when sorter is swapped", () => {
const { skipList, rooms, sorter } = generateSkipList();
const sortedByRecency = [...rooms].sort((a, b) => sorter.comparator(a, b));