Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Always emit a space filter update when the space is actually changed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Jan 24, 2022
1 parent 26e1570 commit e28d2a2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/stores/room-list/filters/SpaceFilterCondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Room } from "matrix-js-sdk/src/models/room";
import { FILTER_CHANGED, FilterKind, IFilterCondition } from "./IFilterCondition";
import { IDestroyable } from "../../../utils/IDestroyable";
import SpaceStore from "../../spaces/SpaceStore";
import { MetaSpace, SpaceKey } from "../../spaces";
import { isMetaSpace, MetaSpace, SpaceKey } from "../../spaces";
import { setHasDiff } from "../../../utils/sets";
import SettingsStore from "../../../settings/SettingsStore";

Expand All @@ -44,7 +44,7 @@ export class SpaceFilterCondition extends EventEmitter implements IFilterConditi
return SpaceStore.instance.isRoomInSpace(this.space, room.roomId);
}

private onStoreUpdate = async (): Promise<void> => {
private onStoreUpdate = async (forceUpdate = false): Promise<void> => {
const beforeRoomIds = this.roomIds;
// clone the set as it may be mutated by the space store internally
this.roomIds = new Set(SpaceStore.instance.getSpaceFilteredRoomIds(this.space));
Expand All @@ -54,10 +54,11 @@ export class SpaceFilterCondition extends EventEmitter implements IFilterConditi
this.userIds = new Set(SpaceStore.instance.getSpaceFilteredUserIds(this.space));

const beforeShowPeopleInSpace = this.showPeopleInSpace;
this.showPeopleInSpace = this.space[0] !== "!" ||
this.showPeopleInSpace = isMetaSpace(this.space[0]) ||
SettingsStore.getValue("Spaces.showPeopleInSpace", this.space);

if (beforeShowPeopleInSpace !== this.showPeopleInSpace ||
if (forceUpdate ||
beforeShowPeopleInSpace !== this.showPeopleInSpace ||
setHasDiff(beforeRoomIds, this.roomIds) ||
setHasDiff(beforeUserIds, this.userIds)
) {
Expand All @@ -73,7 +74,7 @@ export class SpaceFilterCondition extends EventEmitter implements IFilterConditi
public updateSpace(space: SpaceKey) {
SpaceStore.instance.off(this.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 {
Expand Down

0 comments on commit e28d2a2

Please sign in to comment.