From cf58a4376e8b01982ec9b17c0ee50b44fc81d39f Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Sun, 13 Mar 2022 10:37:25 +0530 Subject: [PATCH] Improve roomlist code Signed-off-by: Ajay Bura --- src/client/state/RoomList.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/client/state/RoomList.js b/src/client/state/RoomList.js index bd381552..8f3233c4 100644 --- a/src/client/state/RoomList.js +++ b/src/client/state/RoomList.js @@ -43,13 +43,15 @@ class RoomList extends EventEmitter { getSpaceChildren(roomId) { const space = this.matrixClient.getRoom(roomId); + if (space === null) return null; const mSpaceChild = space?.currentState.getStateEvents('m.space.child'); - const children = mSpaceChild?.map((mEvent) => { + + const children = []; + mSpaceChild.forEach((mEvent) => { const childId = mEvent.event.state_key; - if (isMEventSpaceChild(mEvent)) return childId; - return null; + if (isMEventSpaceChild(mEvent)) children.push(childId); }); - return children?.filter((childId) => childId !== null); + return children; } getCategorizedSpaces(spaceIds) { @@ -69,7 +71,7 @@ class RoomList extends EventEmitter { else mappedChild.add(childId); }); }; - spaceIds.map(categorizeSpace); + spaceIds.forEach(categorizeSpace); return categorized; }