Always emit a space filter update when the space is actually changed (#7611)

This commit is contained in:
Michael Telatynski 2022-01-24 14:45:52 +00:00 committed by GitHub
parent 26e1570dd6
commit e28d2a2299
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -20,7 +20,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { FILTER_CHANGED, FilterKind, IFilterCondition } from "./IFilterCondition"; import { FILTER_CHANGED, FilterKind, IFilterCondition } from "./IFilterCondition";
import { IDestroyable } from "../../../utils/IDestroyable"; import { IDestroyable } from "../../../utils/IDestroyable";
import SpaceStore from "../../spaces/SpaceStore"; import SpaceStore from "../../spaces/SpaceStore";
import { MetaSpace, SpaceKey } from "../../spaces"; import { isMetaSpace, MetaSpace, SpaceKey } from "../../spaces";
import { setHasDiff } from "../../../utils/sets"; import { setHasDiff } from "../../../utils/sets";
import SettingsStore from "../../../settings/SettingsStore"; import SettingsStore from "../../../settings/SettingsStore";
@ -44,7 +44,7 @@ export class SpaceFilterCondition extends EventEmitter implements IFilterConditi
return SpaceStore.instance.isRoomInSpace(this.space, room.roomId); return SpaceStore.instance.isRoomInSpace(this.space, room.roomId);
} }
private onStoreUpdate = async (): Promise<void> => { private onStoreUpdate = async (forceUpdate = false): Promise<void> => {
const beforeRoomIds = this.roomIds; const beforeRoomIds = this.roomIds;
// clone the set as it may be mutated by the space store internally // clone the set as it may be mutated by the space store internally
this.roomIds = new Set(SpaceStore.instance.getSpaceFilteredRoomIds(this.space)); this.roomIds = new Set(SpaceStore.instance.getSpaceFilteredRoomIds(this.space));
@ -54,10 +54,11 @@ export class SpaceFilterCondition extends EventEmitter implements IFilterConditi
this.userIds = new Set(SpaceStore.instance.getSpaceFilteredUserIds(this.space)); this.userIds = new Set(SpaceStore.instance.getSpaceFilteredUserIds(this.space));
const beforeShowPeopleInSpace = this.showPeopleInSpace; const beforeShowPeopleInSpace = this.showPeopleInSpace;
this.showPeopleInSpace = this.space[0] !== "!" || this.showPeopleInSpace = isMetaSpace(this.space[0]) ||
SettingsStore.getValue("Spaces.showPeopleInSpace", this.space); SettingsStore.getValue("Spaces.showPeopleInSpace", this.space);
if (beforeShowPeopleInSpace !== this.showPeopleInSpace || if (forceUpdate ||
beforeShowPeopleInSpace !== this.showPeopleInSpace ||
setHasDiff(beforeRoomIds, this.roomIds) || setHasDiff(beforeRoomIds, this.roomIds) ||
setHasDiff(beforeUserIds, this.userIds) setHasDiff(beforeUserIds, this.userIds)
) { ) {
@ -73,7 +74,7 @@ export class SpaceFilterCondition extends EventEmitter implements IFilterConditi
public updateSpace(space: SpaceKey) { public updateSpace(space: SpaceKey) {
SpaceStore.instance.off(this.space, this.onStoreUpdate); SpaceStore.instance.off(this.space, this.onStoreUpdate);
SpaceStore.instance.on(this.space = space, this.onStoreUpdate); SpaceStore.instance.on(this.space = space, this.onStoreUpdate);
this.onStoreUpdate(); // initial update from the change to the space this.onStoreUpdate(true); // initial update from the change to the space
} }
public destroy(): void { public destroy(): void {