diff --git a/src/app/organisms/navigation/Home.jsx b/src/app/organisms/navigation/Home.jsx index 95bf88e..c52ead4 100644 --- a/src/app/organisms/navigation/Home.jsx +++ b/src/app/organisms/navigation/Home.jsx @@ -15,9 +15,7 @@ const drawerPostie = new Postie(); function Home({ spaceId }) { const mx = initMatrix.matrixClient; const { roomList, notifications, accountData } = initMatrix; - const { - spaces, rooms, directs, roomIdToParents, - } = roomList; + const { spaces, rooms, directs } = roomList; useCategorizedSpaces(); const isCategorized = accountData.categorizedSpaces.has(spaceId); @@ -26,14 +24,14 @@ function Home({ spaceId }) { let roomIds = []; let directIds = []; - const spaceChildIds = roomList.getSpaceChildren(spaceId); - if (spaceChildIds) { + if (spaceId) { + const spaceChildIds = roomList.getSpaceChildren(spaceId); spaceIds = spaceChildIds.filter((roomId) => spaces.has(roomId)); roomIds = spaceChildIds.filter((roomId) => rooms.has(roomId)); directIds = spaceChildIds.filter((roomId) => directs.has(roomId)); } else { - spaceIds = [...spaces].filter((roomId) => !roomIdToParents.has(roomId)); - roomIds = [...rooms].filter((roomId) => !roomIdToParents.has(roomId)); + spaceIds = roomList.getOrphanSpaces(); + roomIds = roomList.getOrphanRooms(); } spaceIds.sort(AtoZ); diff --git a/src/client/state/RoomList.js b/src/client/state/RoomList.js index ec3c060..f1e0d6d 100644 --- a/src/client/state/RoomList.js +++ b/src/client/state/RoomList.js @@ -36,6 +36,14 @@ class RoomList extends EventEmitter { return !this.roomIdToParents.has(roomId); } + getOrphanSpaces() { + return [...this.spaces].filter((roomId) => !this.roomIdToParents.has(roomId)); + } + + getOrphanRooms() { + return [...this.rooms].filter((roomId) => !this.roomIdToParents.has(roomId)); + } + getOrphans() { const rooms = [...this.spaces].concat([...this.rooms]); return rooms.filter((roomId) => !this.roomIdToParents.has(roomId));