Improve roomlist code

Signed-off-by: Ajay Bura <ajbura@gmail.com>
This commit is contained in:
Ajay Bura 2022-03-13 10:37:25 +05:30
parent a76dcb289a
commit cf58a4376e

View file

@ -43,13 +43,15 @@ class RoomList extends EventEmitter {
getSpaceChildren(roomId) { getSpaceChildren(roomId) {
const space = this.matrixClient.getRoom(roomId); const space = this.matrixClient.getRoom(roomId);
if (space === null) return null;
const mSpaceChild = space?.currentState.getStateEvents('m.space.child'); const mSpaceChild = space?.currentState.getStateEvents('m.space.child');
const children = mSpaceChild?.map((mEvent) => {
const children = [];
mSpaceChild.forEach((mEvent) => {
const childId = mEvent.event.state_key; const childId = mEvent.event.state_key;
if (isMEventSpaceChild(mEvent)) return childId; if (isMEventSpaceChild(mEvent)) children.push(childId);
return null;
}); });
return children?.filter((childId) => childId !== null); return children;
} }
getCategorizedSpaces(spaceIds) { getCategorizedSpaces(spaceIds) {
@ -69,7 +71,7 @@ class RoomList extends EventEmitter {
else mappedChild.add(childId); else mappedChild.add(childId);
}); });
}; };
spaceIds.map(categorizeSpace); spaceIds.forEach(categorizeSpace);
return categorized; return categorized;
} }