mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-24 18:59:17 +00:00
Remove unused code left over from the old search (#8947)
This commit is contained in:
committed by
GitHub
parent
424d33d4b0
commit
328d7ea5eb
@@ -26,14 +26,13 @@ import { IListOrderingMap, ITagMap, ITagSortingMap, ListAlgorithm, SortAlgorithm
|
||||
import { ActionPayload } from "../../dispatcher/payloads";
|
||||
import defaultDispatcher from "../../dispatcher/dispatcher";
|
||||
import { readReceiptChangeIsFor } from "../../utils/read-receipts";
|
||||
import { FILTER_CHANGED, FilterKind, IFilterCondition } from "./filters/IFilterCondition";
|
||||
import { FILTER_CHANGED, IFilterCondition } from "./filters/IFilterCondition";
|
||||
import { RoomViewStore } from "../RoomViewStore";
|
||||
import { Algorithm, LIST_UPDATED_EVENT } from "./algorithms/Algorithm";
|
||||
import { EffectiveMembership, getEffectiveMembership } from "../../utils/membership";
|
||||
import RoomListLayoutStore from "./RoomListLayoutStore";
|
||||
import { MarkedExecution } from "../../utils/MarkedExecution";
|
||||
import { AsyncStoreWithClient } from "../AsyncStoreWithClient";
|
||||
import { NameFilterCondition } from "./filters/NameFilterCondition";
|
||||
import { RoomNotificationStateStore } from "../notifications/RoomNotificationStateStore";
|
||||
import { VisibilityProvider } from "./filters/VisibilityProvider";
|
||||
import { SpaceWatcher } from "./SpaceWatcher";
|
||||
@@ -58,7 +57,6 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||
|
||||
private initialListsGenerated = false;
|
||||
private algorithm = new Algorithm();
|
||||
private filterConditions: IFilterCondition[] = [];
|
||||
private prefilterConditions: IFilterCondition[] = [];
|
||||
private updateFn = new MarkedExecution(() => {
|
||||
for (const tagId of Object.keys(this.orderedLists)) {
|
||||
@@ -78,11 +76,6 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||
new SpaceWatcher(this);
|
||||
}
|
||||
|
||||
public get unfilteredLists(): ITagMap {
|
||||
if (!this.algorithm) return {}; // No tags yet.
|
||||
return this.algorithm.getUnfilteredRooms();
|
||||
}
|
||||
|
||||
public get orderedLists(): ITagMap {
|
||||
if (!this.algorithm) return {}; // No tags yet.
|
||||
return this.algorithm.getOrderedRooms();
|
||||
@@ -91,7 +84,6 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||
// Intended for test usage
|
||||
public async resetStore() {
|
||||
await this.reset();
|
||||
this.filterConditions = [];
|
||||
this.prefilterConditions = [];
|
||||
this.initialListsGenerated = false;
|
||||
|
||||
@@ -502,9 +494,7 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||
|
||||
let rooms = this.matrixClient.getVisibleRooms().filter(r => VisibilityProvider.instance.isRoomVisible(r));
|
||||
|
||||
// if spaces are enabled only consider the prefilter conditions when there are no runtime conditions
|
||||
// for the search all spaces feature
|
||||
if (this.prefilterConditions.length > 0 && !this.filterConditions.length) {
|
||||
if (this.prefilterConditions.length > 0) {
|
||||
rooms = rooms.filter(r => {
|
||||
for (const filter of this.prefilterConditions) {
|
||||
if (!filter.isVisible(r)) {
|
||||
@@ -556,20 +546,9 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||
*/
|
||||
public async addFilter(filter: IFilterCondition): Promise<void> {
|
||||
let promise = Promise.resolve();
|
||||
if (filter.kind === FilterKind.Prefilter) {
|
||||
filter.on(FILTER_CHANGED, this.onPrefilterUpdated);
|
||||
this.prefilterConditions.push(filter);
|
||||
promise = this.recalculatePrefiltering();
|
||||
} else {
|
||||
this.filterConditions.push(filter);
|
||||
// Runtime filters with spaces disable prefiltering for the search all spaces feature.
|
||||
// this has to be awaited so that `setKnownRooms` is called in time for the `addFilterCondition` below
|
||||
// this way the runtime filters are only evaluated on one dataset and not both.
|
||||
await this.recalculatePrefiltering();
|
||||
if (this.algorithm) {
|
||||
this.algorithm.addFilterCondition(filter);
|
||||
}
|
||||
}
|
||||
filter.on(FILTER_CHANGED, this.onPrefilterUpdated);
|
||||
this.prefilterConditions.push(filter);
|
||||
promise = this.recalculatePrefiltering();
|
||||
promise.then(() => this.updateFn.trigger());
|
||||
}
|
||||
|
||||
@@ -582,20 +561,8 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||
*/
|
||||
public removeFilter(filter: IFilterCondition): void {
|
||||
let promise = Promise.resolve();
|
||||
let idx = this.filterConditions.indexOf(filter);
|
||||
let removed = false;
|
||||
if (idx >= 0) {
|
||||
this.filterConditions.splice(idx, 1);
|
||||
|
||||
if (this.algorithm) {
|
||||
this.algorithm.removeFilterCondition(filter);
|
||||
}
|
||||
// Runtime filters with spaces disable prefiltering for the search all spaces feature
|
||||
promise = this.recalculatePrefiltering();
|
||||
removed = true;
|
||||
}
|
||||
|
||||
idx = this.prefilterConditions.indexOf(filter);
|
||||
const idx = this.prefilterConditions.indexOf(filter);
|
||||
if (idx >= 0) {
|
||||
filter.off(FILTER_CHANGED, this.onPrefilterUpdated);
|
||||
this.prefilterConditions.splice(idx, 1);
|
||||
@@ -608,20 +575,6 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first (and ideally only) name filter condition. If one isn't present,
|
||||
* this returns null.
|
||||
* @returns The first name filter condition, or null if none.
|
||||
*/
|
||||
public getFirstNameFilterCondition(): NameFilterCondition | null {
|
||||
for (const filter of this.filterConditions) {
|
||||
if (filter instanceof NameFilterCondition) {
|
||||
return filter;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the tags for a room identified by the store. The returned set
|
||||
* should never be empty, and will contain DefaultTagID.Untagged if
|
||||
|
||||
@@ -30,7 +30,6 @@ import {
|
||||
ListAlgorithm,
|
||||
SortAlgorithm,
|
||||
} from "./models";
|
||||
import { FILTER_CHANGED, IFilterCondition } from "../filters/IFilterCondition";
|
||||
import { EffectiveMembership, getEffectiveMembership, splitRoomsByMembership } from "../../../utils/membership";
|
||||
import { OrderingAlgorithm } from "./list-ordering/OrderingAlgorithm";
|
||||
import { getListAlgorithmInstance } from "./list-ordering";
|
||||
@@ -67,7 +66,6 @@ interface IStickyRoom {
|
||||
export class Algorithm extends EventEmitter {
|
||||
private _cachedRooms: ITagMap = {};
|
||||
private _cachedStickyRooms: ITagMap = {}; // a clone of the _cachedRooms, with the sticky room
|
||||
private filteredRooms: ITagMap = {};
|
||||
private _stickyRoom: IStickyRoom = null;
|
||||
private _lastStickyRoom: IStickyRoom = null; // only not-null when changing the sticky room
|
||||
private sortAlgorithms: ITagSortingMap;
|
||||
@@ -77,8 +75,6 @@ export class Algorithm extends EventEmitter {
|
||||
private roomIdsToTags: {
|
||||
[roomId: string]: TagID[];
|
||||
} = {};
|
||||
private allowedByFilter: Map<IFilterCondition, Room[]> = new Map<IFilterCondition, Room[]>();
|
||||
private allowedRoomsByFilters: Set<Room> = new Set<Room>();
|
||||
|
||||
/**
|
||||
* Set to true to suspend emissions of algorithm updates.
|
||||
@@ -107,13 +103,8 @@ export class Algorithm extends EventEmitter {
|
||||
return !!this.sortAlgorithms;
|
||||
}
|
||||
|
||||
protected get hasFilters(): boolean {
|
||||
return this.allowedByFilter.size > 0;
|
||||
}
|
||||
|
||||
protected set cachedRooms(val: ITagMap) {
|
||||
this._cachedRooms = val;
|
||||
this.recalculateFilteredRooms();
|
||||
this.recalculateStickyRoom();
|
||||
this.recalculateVideoRoom();
|
||||
}
|
||||
@@ -151,7 +142,6 @@ export class Algorithm extends EventEmitter {
|
||||
const algorithm: OrderingAlgorithm = this.algorithms[tagId];
|
||||
algorithm.setSortAlgorithm(sort);
|
||||
this._cachedRooms[tagId] = algorithm.orderedRooms;
|
||||
this.recalculateFilteredRoomsForTag(tagId); // update filter to re-sort the list
|
||||
this.recalculateStickyRoom(tagId); // update sticky room to make sure it appears if needed
|
||||
this.recalculateVideoRoom(tagId);
|
||||
}
|
||||
@@ -171,40 +161,10 @@ export class Algorithm extends EventEmitter {
|
||||
|
||||
algorithm.setRooms(this._cachedRooms[tagId]);
|
||||
this._cachedRooms[tagId] = algorithm.orderedRooms;
|
||||
this.recalculateFilteredRoomsForTag(tagId); // update filter to re-sort the list
|
||||
this.recalculateStickyRoom(tagId); // update sticky room to make sure it appears if needed
|
||||
this.recalculateVideoRoom(tagId);
|
||||
}
|
||||
|
||||
public addFilterCondition(filterCondition: IFilterCondition): void {
|
||||
// Populate the cache of the new filter
|
||||
this.allowedByFilter.set(filterCondition, this.rooms.filter(r => filterCondition.isVisible(r)));
|
||||
this.recalculateFilteredRooms();
|
||||
filterCondition.on(FILTER_CHANGED, this.handleFilterChange.bind(this));
|
||||
}
|
||||
|
||||
public removeFilterCondition(filterCondition: IFilterCondition): void {
|
||||
filterCondition.off(FILTER_CHANGED, this.handleFilterChange.bind(this));
|
||||
if (this.allowedByFilter.has(filterCondition)) {
|
||||
this.allowedByFilter.delete(filterCondition);
|
||||
this.recalculateFilteredRooms();
|
||||
|
||||
// If we removed the last filter, tell consumers that we've "updated" our filtered
|
||||
// view. This will trick them into getting the complete room list.
|
||||
if (!this.hasFilters && !this.updatesInhibited) {
|
||||
this.emit(LIST_UPDATED_EVENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private handleFilterChange() {
|
||||
this.recalculateFilteredRooms();
|
||||
|
||||
// re-emit the update so the list store can fire an off-cycle update if needed
|
||||
if (this.updatesInhibited) return;
|
||||
this.emit(FILTER_CHANGED);
|
||||
}
|
||||
|
||||
private updateStickyRoom(val: Room) {
|
||||
this.doUpdateStickyRoom(val);
|
||||
this._lastStickyRoom = null; // clear to indicate we're done changing
|
||||
@@ -318,8 +278,6 @@ export class Algorithm extends EventEmitter {
|
||||
// We update the filtered rooms just in case, as otherwise users will end up visiting
|
||||
// a room while filtering and it'll disappear. We don't update the filter earlier in
|
||||
// this function simply because we don't have to.
|
||||
this.recalculateFilteredRoomsForTag(tag);
|
||||
if (lastStickyRoom && lastStickyRoom.tag !== tag) this.recalculateFilteredRoomsForTag(lastStickyRoom.tag);
|
||||
this.recalculateStickyRoom();
|
||||
this.recalculateVideoRoom(tag);
|
||||
if (lastStickyRoom && lastStickyRoom.tag !== tag) this.recalculateVideoRoom(lastStickyRoom.tag);
|
||||
@@ -334,7 +292,6 @@ export class Algorithm extends EventEmitter {
|
||||
*/
|
||||
public updateVideoRoom = () => {
|
||||
// In case we're unsticking a video room, sort it back into natural order
|
||||
this.recalculateFilteredRooms();
|
||||
this.recalculateStickyRoom();
|
||||
|
||||
this.recalculateVideoRoom();
|
||||
@@ -345,63 +302,6 @@ export class Algorithm extends EventEmitter {
|
||||
this.emit(LIST_UPDATED_EVENT, true);
|
||||
};
|
||||
|
||||
protected recalculateFilteredRooms() {
|
||||
if (!this.hasFilters) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.warn("Recalculating filtered room list");
|
||||
const filters = Array.from(this.allowedByFilter.keys());
|
||||
const newMap: ITagMap = {};
|
||||
for (const tagId of Object.keys(this.cachedRooms)) {
|
||||
// Cheaply clone the rooms so we can more easily do operations on the list.
|
||||
// We optimize our lookups by trying to reduce sample size as much as possible
|
||||
// to the rooms we know will be deduped by the Set.
|
||||
const rooms = this.cachedRooms[tagId].map(r => r); // cheap clone
|
||||
this.tryInsertStickyRoomToFilterSet(rooms, tagId);
|
||||
const remainingRooms = rooms.map(r => r);
|
||||
const allowedRoomsInThisTag = [];
|
||||
for (const filter of filters) {
|
||||
const filteredRooms = remainingRooms.filter(r => filter.isVisible(r));
|
||||
for (const room of filteredRooms) {
|
||||
const idx = remainingRooms.indexOf(room);
|
||||
if (idx >= 0) remainingRooms.splice(idx, 1);
|
||||
allowedRoomsInThisTag.push(room);
|
||||
}
|
||||
}
|
||||
newMap[tagId] = allowedRoomsInThisTag;
|
||||
}
|
||||
|
||||
const allowedRooms = Object.values(newMap).reduce((rv, v) => { rv.push(...v); return rv; }, <Room[]>[]);
|
||||
this.allowedRoomsByFilters = new Set(allowedRooms);
|
||||
this.filteredRooms = newMap;
|
||||
if (this.updatesInhibited) return;
|
||||
this.emit(LIST_UPDATED_EVENT);
|
||||
}
|
||||
|
||||
protected recalculateFilteredRoomsForTag(tagId: TagID): void {
|
||||
if (!this.hasFilters) return; // don't bother doing work if there's nothing to do
|
||||
|
||||
delete this.filteredRooms[tagId];
|
||||
const rooms = this.cachedRooms[tagId].map(r => r); // cheap clone
|
||||
this.tryInsertStickyRoomToFilterSet(rooms, tagId);
|
||||
const filteredRooms = rooms.filter(r => this.allowedRoomsByFilters.has(r));
|
||||
if (filteredRooms.length > 0) {
|
||||
this.filteredRooms[tagId] = filteredRooms;
|
||||
}
|
||||
}
|
||||
|
||||
protected tryInsertStickyRoomToFilterSet(rooms: Room[], tagId: TagID) {
|
||||
if (!this._stickyRoom || !this._stickyRoom.room || this._stickyRoom.tag !== tagId) return;
|
||||
|
||||
const position = this._stickyRoom.position;
|
||||
if (position >= rooms.length) {
|
||||
rooms.push(this._stickyRoom.room);
|
||||
} else {
|
||||
rooms.splice(position, 0, this._stickyRoom.room);
|
||||
}
|
||||
}
|
||||
|
||||
private initCachedStickyRooms() {
|
||||
this._cachedStickyRooms = {};
|
||||
for (const tagId of Object.keys(this.cachedRooms)) {
|
||||
@@ -520,18 +420,11 @@ export class Algorithm extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an ordered set of rooms for the all known tags, filtered.
|
||||
* Gets an ordered set of rooms for the all known tags.
|
||||
* @returns {ITagMap} The cached list of rooms, ordered,
|
||||
* for each tag. May be empty, but never null/undefined.
|
||||
*/
|
||||
public getOrderedRooms(): ITagMap {
|
||||
if (!this.hasFilters) {
|
||||
return this._cachedStickyRooms || this.cachedRooms;
|
||||
}
|
||||
return this.filteredRooms;
|
||||
}
|
||||
|
||||
public getUnfilteredRooms(): ITagMap {
|
||||
return this._cachedStickyRooms || this.cachedRooms;
|
||||
}
|
||||
|
||||
@@ -543,10 +436,7 @@ export class Algorithm extends EventEmitter {
|
||||
* for each tag. May be empty, but never null/undefined.
|
||||
*/
|
||||
private getOrderedRoomsWithoutSticky(): ITagMap {
|
||||
if (!this.hasFilters) {
|
||||
return this.cachedRooms;
|
||||
}
|
||||
return this.filteredRooms;
|
||||
return this.cachedRooms;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -775,7 +665,6 @@ export class Algorithm extends EventEmitter {
|
||||
if (!algorithm) throw new Error(`No algorithm for ${rmTag}`);
|
||||
algorithm.handleRoomUpdate(room, RoomUpdateCause.RoomRemoved);
|
||||
this._cachedRooms[rmTag] = algorithm.orderedRooms;
|
||||
this.recalculateFilteredRoomsForTag(rmTag); // update filter to re-sort the list
|
||||
this.recalculateStickyRoom(rmTag); // update sticky room to make sure it moves if needed
|
||||
this.recalculateVideoRoom(rmTag);
|
||||
}
|
||||
@@ -852,7 +741,6 @@ export class Algorithm extends EventEmitter {
|
||||
this._cachedRooms[tag] = algorithm.orderedRooms;
|
||||
|
||||
// Flag that we've done something
|
||||
this.recalculateFilteredRoomsForTag(tag); // update filter to re-sort the list
|
||||
this.recalculateStickyRoom(tag); // update sticky room to make sure it appears if needed
|
||||
this.recalculateVideoRoom(tag);
|
||||
changed = true;
|
||||
|
||||
@@ -19,21 +19,6 @@ import { EventEmitter } from "events";
|
||||
|
||||
export const FILTER_CHANGED = "filter_changed";
|
||||
|
||||
export enum FilterKind {
|
||||
/**
|
||||
* A prefilter is one which coarsely determines which rooms are
|
||||
* available for runtime filtering/rendering. Typically this will
|
||||
* be things like Space selection.
|
||||
*/
|
||||
Prefilter,
|
||||
|
||||
/**
|
||||
* Runtime filters operate on the data set exposed by prefilters.
|
||||
* Typically these are dynamic values like room name searching.
|
||||
*/
|
||||
Runtime,
|
||||
}
|
||||
|
||||
/**
|
||||
* A filter condition for the room list, determining if a room
|
||||
* should be shown or not.
|
||||
@@ -47,11 +32,6 @@ export enum FilterKind {
|
||||
* as a change in the user's input), this emits FILTER_CHANGED.
|
||||
*/
|
||||
export interface IFilterCondition extends EventEmitter {
|
||||
/**
|
||||
* The kind of filter this presents.
|
||||
*/
|
||||
kind: FilterKind;
|
||||
|
||||
/**
|
||||
* Determines if a given room should be visible under this
|
||||
* condition.
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
Copyright 2020, 2021 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { EventEmitter } from "events";
|
||||
import { normalize } from "matrix-js-sdk/src/utils";
|
||||
import { throttle } from "lodash";
|
||||
|
||||
import { FILTER_CHANGED, FilterKind, IFilterCondition } from "./IFilterCondition";
|
||||
|
||||
/**
|
||||
* A filter condition for the room list which reveals rooms of a particular
|
||||
* name, or associated name (like a room alias).
|
||||
*/
|
||||
export class NameFilterCondition extends EventEmitter implements IFilterCondition {
|
||||
private _search = "";
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public get kind(): FilterKind {
|
||||
return FilterKind.Runtime;
|
||||
}
|
||||
|
||||
public get search(): string {
|
||||
return this._search;
|
||||
}
|
||||
|
||||
public set search(val: string) {
|
||||
this._search = val;
|
||||
this.callUpdate();
|
||||
}
|
||||
|
||||
private callUpdate = throttle(() => {
|
||||
this.emit(FILTER_CHANGED);
|
||||
}, 200, { trailing: true, leading: true });
|
||||
|
||||
public isVisible(room: Room): boolean {
|
||||
const lcFilter = this.search.toLowerCase();
|
||||
if (this.search[0] === '#') {
|
||||
// Try and find rooms by alias
|
||||
if (room.getCanonicalAlias() && room.getCanonicalAlias().toLowerCase().startsWith(lcFilter)) {
|
||||
return true;
|
||||
}
|
||||
if (room.getAltAliases().some(a => a.toLowerCase().startsWith(lcFilter))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!room.name) return false; // should realistically not happen: the js-sdk always calculates a name
|
||||
|
||||
return this.matches(room.normalizedName);
|
||||
}
|
||||
|
||||
public matches(normalizedName: string): boolean {
|
||||
return normalizedName.includes(normalize(this.search));
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ limitations under the License.
|
||||
import { EventEmitter } from "events";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
|
||||
import { FILTER_CHANGED, FilterKind, IFilterCondition } from "./IFilterCondition";
|
||||
import { FILTER_CHANGED, IFilterCondition } from "./IFilterCondition";
|
||||
import { IDestroyable } from "../../../utils/IDestroyable";
|
||||
import SpaceStore from "../../spaces/SpaceStore";
|
||||
import { isMetaSpace, MetaSpace, SpaceKey } from "../../spaces";
|
||||
@@ -36,10 +36,6 @@ export class SpaceFilterCondition extends EventEmitter implements IFilterConditi
|
||||
private showPeopleInSpace = true;
|
||||
private space: SpaceKey = MetaSpace.Home;
|
||||
|
||||
public get kind(): FilterKind {
|
||||
return FilterKind.Prefilter;
|
||||
}
|
||||
|
||||
public isVisible(room: Room): boolean {
|
||||
return SpaceStore.instance.isRoomInSpace(this.space, room.roomId);
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
||||
metricsTrigger: "WebSpacePanelNotificationBadge",
|
||||
});
|
||||
} else {
|
||||
const lists = RoomListStore.instance.unfilteredLists;
|
||||
const lists = RoomListStore.instance.orderedLists;
|
||||
for (let i = 0; i < TAG_ORDER.length; i++) {
|
||||
const t = TAG_ORDER[i];
|
||||
const listRooms = lists[t];
|
||||
|
||||
Reference in New Issue
Block a user