Add bot-driven room app UI via im.paarrot.ui state.
All checks were successful
Trigger cinny-mobile / dispatch (push) Successful in 2s
All checks were successful
Trigger cinny-mobile / dispatch (push) Successful in 2s
Bots can publish a declarative panel UI that takes over a room; user actions are sent as im.paarrot.ui.action timeline events.
This commit is contained in:
@@ -24,6 +24,7 @@ import {
|
||||
Membership,
|
||||
MessageEvent,
|
||||
NotificationType,
|
||||
PaarrotUiContent,
|
||||
RoomToParents,
|
||||
RoomType,
|
||||
StateEvent,
|
||||
@@ -125,6 +126,33 @@ export const getPaarrotRoomKind = (room: Room | null): string | undefined => {
|
||||
return typeof kind === 'string' ? kind : undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Valid bot-driven room UI state (im.paarrot.ui with version + root node).
|
||||
*/
|
||||
export const parsePaarrotUiContent = (raw: unknown): PaarrotUiContent | undefined => {
|
||||
if (!raw || typeof raw !== 'object') return undefined;
|
||||
const content = raw as PaarrotUiContent;
|
||||
if (
|
||||
typeof content.version !== 'number' ||
|
||||
!content.root ||
|
||||
typeof content.root !== 'object' ||
|
||||
typeof content.root.type !== 'string' ||
|
||||
typeof content.root.id !== 'string'
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
return content;
|
||||
};
|
||||
|
||||
export const getPaarrotUiContent = (room: Room | null): PaarrotUiContent | undefined => {
|
||||
if (!room) return undefined;
|
||||
const event = room.currentState?.getStateEvents(StateEvent.PaarrotUi, '');
|
||||
if (!event) return undefined;
|
||||
return parsePaarrotUiContent(event.getContent());
|
||||
};
|
||||
|
||||
export const hasRoomAppUi = (room: Room | null): boolean => getPaarrotUiContent(room) !== 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;
|
||||
|
||||
Reference in New Issue
Block a user