feat: Integrate forum layout support across various components and enhance room handling logic

This commit is contained in:
2026-07-06 01:06:20 +10:00
parent d1626e3585
commit c57797ffe4
62 changed files with 6876 additions and 385 deletions

View File

@@ -72,25 +72,101 @@ export const isDirectInvite = (room: Room | null, myUserId: string | null): bool
return content?.is_direct === true;
};
/**
* Read room create type with a resilient fallback for rooms whose live timeline state
* does not currently expose m.room.create.
*/
const getRoomCreateType = (room: Room): string | undefined => {
const roomKindEvent = room.currentState?.getStateEvents(StateEvent.PaarrotRoomKind, '');
const roomKind = roomKindEvent?.getContent<{ kind?: string }>()?.kind;
if (roomKind === 'forum_space') {
return RoomType.Forum;
}
const liveCreate = getStateEvent(room, StateEvent.RoomCreate);
const liveType = liveCreate?.getContent<{ type?: string }>()?.type;
if (typeof liveType === 'string') {
return liveType;
}
const stateCreate = room.currentState?.getStateEvents(StateEvent.RoomCreate, '');
const stateType = stateCreate?.getContent<{ type?: string }>()?.type;
if (typeof stateType === 'string') {
return stateType;
}
return undefined;
};
export const isSpace = (room: Room | null): boolean => {
if (!room) return false;
const event = getStateEvent(room, StateEvent.RoomCreate);
if (!event) return false;
return event.getContent().type === RoomType.Space;
const roomType = getRoomCreateType(room);
return roomType === RoomType.Space || roomType === RoomType.Forum;
};
export const isForum = (room: Room | null): boolean => {
if (!room) return false;
return getRoomCreateType(room) === RoomType.Forum;
};
export const getPaarrotRoomKind = (room: Room | null): string | undefined => {
if (!room) return undefined;
const kind = room.currentState
?.getStateEvents(StateEvent.PaarrotRoomKind, '')
?.getContent<{ kind?: string }>()?.kind;
return typeof kind === 'string' ? kind : undefined;
};
/**
* m.forum space root (forum board lobby), not a plain m.space or a lone m.forum topic channel.
* Matrix sets create type m.forum on forum spaces but SDK isSpaceRoom() is often still false;
* those rooms still have m.space.child entries like a normal space.
*/
export const isForumContainer = (room: Room | null): boolean => {
if (!room) return false;
if (getPaarrotRoomKind(room) === 'forum_space') return true;
if (getRoomCreateType(room) !== RoomType.Forum) return false;
if (room.isSpaceRoom()) return true;
return getSpaceChildren(room).length > 0;
};
/** @deprecated Use isForumContainer */
export const isForumSpace = isForumContainer;
export const shouldShowForumLobby = isForumContainer;
/** Nearest m.forum / forum_space ancestor for a topic room. */
export const findForumRootSpace = (
mx: MatrixClient,
roomId: string,
roomToParents: RoomToParents
): string | undefined => {
const ordered = [roomId, ...Array.from(getAllParents(roomToParents, roomId))];
for (const id of ordered) {
const room = mx.getRoom(id);
if (room && shouldShowForumLobby(room)) return id;
}
return undefined;
};
/** @deprecated Use findForumRootSpace */
export const findForumSpaceAncestor = findForumRootSpace;
export const isRoom = (room: Room | null): boolean => {
if (!room) return false;
const event = getStateEvent(room, StateEvent.RoomCreate);
if (!event) return true;
return event.getContent().type !== RoomType.Space;
const roomType = getRoomCreateType(room);
if (!roomType) return true;
return roomType !== RoomType.Space && roomType !== RoomType.Forum;
};
export const isUnsupportedRoom = (room: Room | null): boolean => {
if (!room) return false;
const event = getStateEvent(room, StateEvent.RoomCreate);
if (!event) return true; // Consider room unsupported if m.room.create event doesn't exist
return event.getContent().type !== undefined && event.getContent().type !== RoomType.Space;
const roomType = getRoomCreateType(room);
if (!roomType) return true; // Consider room unsupported if m.room.create event doesn't exist
return (
roomType !== RoomType.Space &&
roomType !== RoomType.Forum
);
};
export function isValidChild(mEvent: MatrixEvent): boolean {