Improve roomlist code
authorAjay Bura <ajbura@gmail.com>
Sun, 13 Mar 2022 05:07:25 +0000 (10:37 +0530)
committerAjay Bura <ajbura@gmail.com>
Sun, 13 Mar 2022 05:07:25 +0000 (10:37 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/client/state/RoomList.js

index bd3815529e3f665d82b4b69701984242545d562d..8f3233c4279c2a7cdc47a9246fe233f85c3bbe8e 100644 (file)
@@ -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;
   }