From a2fe964a31ebe6b9b8849c237d7270f7f5c5d0a3 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 25 Mar 2021 17:37:39 +0000 Subject: [PATCH] Fix case where room list did not show DM when user joined space after filtering --- src/stores/SpaceStore.tsx | 42 ++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/stores/SpaceStore.tsx b/src/stores/SpaceStore.tsx index bcf95a82be..02c6c99bb9 100644 --- a/src/stores/SpaceStore.tsx +++ b/src/stores/SpaceStore.tsx @@ -294,6 +294,12 @@ export class SpaceStoreClass extends AsyncStoreWithClient { } }; + private onSpaceMembersChange = (space: Room, ev: MatrixEvent) => { + // skip this update if we do not have a DM with this user + if (DMRoomMap.shared().getDMRoomsForUserId(ev.getStateKey()).length < 1) return; + this.onRoomsUpdate(); + }; + private onRoomsUpdate = throttle(() => { // TODO resolve some updates as deltas const visibleRooms = this.matrixClient.getVisibleRooms(); @@ -385,18 +391,30 @@ export class SpaceStoreClass extends AsyncStoreWithClient { const room = this.matrixClient.getRoom(ev.getRoomId()); if (!room) return; - if (ev.getType() === EventType.SpaceChild && room.isSpaceRoom()) { - this.onSpaceUpdate(); - this.emit(room.roomId); - } else if (ev.getType() === EventType.SpaceParent) { - // TODO rebuild the space parent and not the room - check permissions? - // TODO confirm this after implementing parenting behaviour - if (room.isSpaceRoom()) { - this.onSpaceUpdate(); - } else { - this.onRoomUpdate(room); - } - this.emit(room.roomId); + switch (ev.getType()) { + case EventType.SpaceChild: + if (room.isSpaceRoom()) { + this.onSpaceUpdate(); + this.emit(room.roomId); + } + break; + + case EventType.SpaceParent: + // TODO rebuild the space parent and not the room - check permissions? + // TODO confirm this after implementing parenting behaviour + if (room.isSpaceRoom()) { + this.onSpaceUpdate(); + } else { + this.onRoomUpdate(room); + } + this.emit(room.roomId); + break; + + case EventType.RoomMember: + if (room.isSpaceRoom()) { + this.onSpaceMembersChange(room, ev); + } + break; } };