mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-04 19:56:45 +02:00
feat: add in skip list a method to change filters
This commit is contained in:
parent
68031f4246
commit
b95d5f89ec
@ -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.
|
||||
*/
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user