mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-15 11:40:29 +03:00
show space header if subspaces contain rooms
This commit is contained in:
parent
ae75ee7fc3
commit
18082ff400
1 changed files with 24 additions and 1 deletions
|
|
@ -198,6 +198,29 @@ const getSpaceJoinedHierarchy = (
|
||||||
new Set()
|
new Set()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively checks if the given space or any of its descendants contain non-space rooms.
|
||||||
|
*
|
||||||
|
* @param roomId - The space ID to check.
|
||||||
|
* @returns True if the space or any descendant contains non-space rooms.
|
||||||
|
*/
|
||||||
|
const containsRoom = (spaceId: string) => {
|
||||||
|
const space = getRoom(spaceId);
|
||||||
|
if (!space) return false;
|
||||||
|
|
||||||
|
const childEvents = getStateEvents(space, StateEvent.SpaceChild).filter(isValidChild);
|
||||||
|
|
||||||
|
return childEvents.some((childEvent): boolean => {
|
||||||
|
const childId = childEvent.getStateKey();
|
||||||
|
if (!childId || !isRoomId(childId)) return false;
|
||||||
|
const room = getRoom(childId);
|
||||||
|
if (!room) return false;
|
||||||
|
|
||||||
|
if (!room.isSpaceRoom()) return true;
|
||||||
|
return containsRoom(childId);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const hierarchy: HierarchyItem[] = spaceItems.flatMap((spaceItem) => {
|
const hierarchy: HierarchyItem[] = spaceItems.flatMap((spaceItem) => {
|
||||||
const space = getRoom(spaceItem.roomId);
|
const space = getRoom(spaceItem.roomId);
|
||||||
if (!space) {
|
if (!space) {
|
||||||
|
|
@ -213,7 +236,7 @@ const getSpaceJoinedHierarchy = (
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (joinedRoomEvents.length === 0) return [];
|
if (!containsRoom(spaceItem.roomId)) return [];
|
||||||
|
|
||||||
const childItems: HierarchyItemRoom[] = [];
|
const childItems: HierarchyItemRoom[] = [];
|
||||||
joinedRoomEvents.forEach((childEvent) => {
|
joinedRoomEvents.forEach((childEvent) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue