mirror of https://github.com/vector-im/riot-web
Merge pull request #5882 from matrix-org/t3chguy/fix/17002
Trigger lazy loading when filtering using spacespull/21833/head
commit
6127669c53
|
@ -525,6 +525,26 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
this.notificationStateMap.set(key, state);
|
this.notificationStateMap.set(key, state);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// traverse space tree with DFS calling fn on each space including the given root one
|
||||||
|
public traverseSpace(
|
||||||
|
spaceId: string,
|
||||||
|
fn: (roomId: string) => void,
|
||||||
|
includeRooms = false,
|
||||||
|
parentPath?: Set<string>,
|
||||||
|
) {
|
||||||
|
if (parentPath && parentPath.has(spaceId)) return; // prevent cycles
|
||||||
|
|
||||||
|
fn(spaceId);
|
||||||
|
|
||||||
|
const newPath = new Set(parentPath).add(spaceId);
|
||||||
|
const [childSpaces, childRooms] = partitionSpacesAndRooms(this.getChildren(spaceId));
|
||||||
|
|
||||||
|
if (includeRooms) {
|
||||||
|
childRooms.forEach(r => fn(r.roomId));
|
||||||
|
}
|
||||||
|
childSpaces.forEach(s => this.traverseSpace(s.roomId, fn, includeRooms, newPath));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class SpaceStore {
|
export default class SpaceStore {
|
||||||
|
|
|
@ -28,12 +28,22 @@ export class SpaceWatcher {
|
||||||
private activeSpace: Room = SpaceStore.instance.activeSpace;
|
private activeSpace: Room = SpaceStore.instance.activeSpace;
|
||||||
|
|
||||||
constructor(private store: RoomListStoreClass) {
|
constructor(private store: RoomListStoreClass) {
|
||||||
this.filter.updateSpace(this.activeSpace); // get the filter into a consistent state
|
this.updateFilter(); // get the filter into a consistent state
|
||||||
store.addFilter(this.filter);
|
store.addFilter(this.filter);
|
||||||
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdated);
|
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.onSelectedSpaceUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onSelectedSpaceUpdated = (activeSpace) => {
|
private onSelectedSpaceUpdated = (activeSpace: Room) => {
|
||||||
this.filter.updateSpace(this.activeSpace = activeSpace);
|
this.activeSpace = activeSpace;
|
||||||
|
this.updateFilter();
|
||||||
|
};
|
||||||
|
|
||||||
|
private updateFilter = () => {
|
||||||
|
if (this.activeSpace) {
|
||||||
|
SpaceStore.instance.traverseSpace(this.activeSpace.roomId, roomId => {
|
||||||
|
this.store.matrixClient?.getRoom(roomId)?.loadMembersIfNeeded();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.filter.updateSpace(this.activeSpace);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue