From 5e9b45ad5fd8f5ac04fbaff5f491762e1afb01b0 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Mon, 14 Mar 2022 17:29:40 +0530 Subject: [PATCH] Fix roomlist not updating when adding space cycle Signed-off-by: Ajay Bura --- src/client/state/RoomList.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/client/state/RoomList.js b/src/client/state/RoomList.js index 0153c45..e200aac 100644 --- a/src/client/state/RoomList.js +++ b/src/client/state/RoomList.js @@ -111,20 +111,21 @@ class RoomList extends EventEmitter { addToSpaces(roomId) { this.spaces.add(roomId); - const allParentSpaces = this.getParentSpaces(roomId); + const allParentSpaces = this.getAllParentSpaces(roomId); const spaceChildren = this.getSpaceChildren(roomId); - spaceChildren?.forEach((childRoomId) => { - if (allParentSpaces.has(childRoomId)) return; - this.addToRoomIdToParents(childRoomId, roomId); + spaceChildren?.forEach((childId) => { + if (allParentSpaces.has(childId)) return; + this.addToRoomIdToParents(childId, roomId); }); } deleteFromSpaces(roomId) { this.spaces.delete(roomId); + const spaceChildren = this.getSpaceChildren(roomId); - spaceChildren?.forEach((childRoomId) => { - this.removeFromRoomIdToParents(childRoomId, roomId); + spaceChildren?.forEach((childId) => { + this.removeFromRoomIdToParents(childId, roomId); }); } @@ -264,12 +265,17 @@ class RoomList extends EventEmitter { this.matrixClient.on('RoomState.events', (mEvent, state) => { if (mEvent.getType() === 'm.space.child') { - const { event } = mEvent; + const roomId = mEvent.event.room_id; + const childId = mEvent.event.state_key; if (isMEventSpaceChild(mEvent)) { - const allParentSpaces = this.getParentSpaces(event.room_id); - if (allParentSpaces.has(event.state_key)) return; - this.addToRoomIdToParents(event.state_key, event.room_id); - } else this.removeFromRoomIdToParents(event.state_key, event.room_id); + const allParentSpaces = this.getAllParentSpaces(roomId); + // only add if it doesn't make a cycle + if (!allParentSpaces.has(childId)) { + this.addToRoomIdToParents(childId, roomId); + } + } else { + this.removeFromRoomIdToParents(childId, roomId); + } this.emit(cons.events.roomList.ROOMLIST_UPDATED); return; }