UNPKG

matrix-react-sdk

Version:
117 lines (116 loc) 6.06 kB
import { IWidget, IWidgetData } from "matrix-widget-api"; import { Room, MatrixClient, MatrixEvent } from "matrix-js-sdk/src/matrix"; import { CallType } from "matrix-js-sdk/src/webrtc/call"; import { WidgetType } from "../widgets/WidgetType"; import { IApp } from "../stores/WidgetStore"; export interface IWidgetEvent { id: string; type: string; sender: string; state_key: string; content: IApp; } export interface UserWidget extends Omit<IWidgetEvent, "content"> { content: IWidget & Partial<IApp>; } export default class WidgetUtils { /** * Returns true if user is able to send state events to modify widgets in this room * (Does not apply to non-room-based / user widgets) * @param client The matrix client of the logged-in user * @param roomId -- The ID of the room to check * @return Boolean -- true if the user can modify widgets in this room * @throws Error -- specifies the error reason */ static canUserModifyWidgets(client: MatrixClient, roomId?: string): boolean; /** * Returns true if specified url is a scalar URL, typically https://scalar.vector.im/api * @param matrixClient The matrix client of the logged-in user * @param {[type]} testUrlString URL to check * @return {Boolean} True if specified URL is a scalar URL */ static isScalarUrl(testUrlString?: string): boolean; /** * Returns a promise that resolves when a widget with the given * ID has been added as a user widget (ie. the accountData event * arrives) or rejects after a timeout * * @param client The matrix client of the logged-in user * @param widgetId The ID of the widget to wait for * @param add True to wait for the widget to be added, * false to wait for it to be deleted. * @returns {Promise} that resolves when the widget is in the * requested state according to the `add` param */ static waitForUserWidget(client: MatrixClient, widgetId: string, add: boolean): Promise<void>; /** * Returns a promise that resolves when a widget with the given * ID has been added as a room widget in the given room (ie. the * room state event arrives) or rejects after a timeout * * @param client The matrix client of the logged-in user * @param {string} widgetId The ID of the widget to wait for * @param {string} roomId The ID of the room to wait for the widget in * @param {boolean} add True to wait for the widget to be added, * false to wait for it to be deleted. * @returns {Promise} that resolves when the widget is in the * requested state according to the `add` param */ static waitForRoomWidget(client: MatrixClient, widgetId: string, roomId: string, add: boolean): Promise<void>; static setUserWidget(client: MatrixClient, widgetId: string, widgetType: WidgetType, widgetUrl: string, widgetName: string, widgetData: IWidgetData): Promise<void>; static setRoomWidget(client: MatrixClient, roomId: string, widgetId: string, widgetType?: WidgetType, widgetUrl?: string, widgetName?: string, widgetData?: IWidgetData, widgetAvatarUrl?: string): Promise<void>; static setRoomWidgetContent(client: MatrixClient, roomId: string, widgetId: string, content: IWidget & Record<string, any>): Promise<void>; /** * Get room specific widgets * @param {Room} room The room to get widgets force * @return {[object]} Array containing current / active room widgets */ static getRoomWidgets(room: Room): MatrixEvent[]; /** * Get user specific widgets (not linked to a specific room) * @param client The matrix client of the logged-in user * @return {object} Event content object containing current / active user widgets */ static getUserWidgets(client: MatrixClient | undefined): Record<string, UserWidget>; /** * Get user specific widgets (not linked to a specific room) as an array * @param client The matrix client of the logged-in user * @return {[object]} Array containing current / active user widgets */ static getUserWidgetsArray(client: MatrixClient | undefined): UserWidget[]; /** * Get active stickerpicker widgets (stickerpickers are user widgets by nature) * @param client The matrix client of the logged-in user * @return {[object]} Array containing current / active stickerpicker widgets */ static getStickerpickerWidgets(client: MatrixClient | undefined): UserWidget[]; /** * Get all integration manager widgets for this user. * @param client The matrix client of the logged-in user * @returns {Object[]} An array of integration manager user widgets. */ static getIntegrationManagerWidgets(client: MatrixClient | undefined): UserWidget[]; /** * Remove all stickerpicker widgets (stickerpickers are user widgets by nature) * @param client The matrix client of the logged-in user * @return {Promise} Resolves on account data updated */ static removeStickerpickerWidgets(client: MatrixClient | undefined): Promise<void>; static addJitsiWidget(client: MatrixClient, roomId: string, type: CallType, name: string, isVideoChannel: boolean, oobRoomName?: string): Promise<void>; static makeAppConfig(appId: string, app: Partial<IApp>, senderUserId: string, roomId: string | undefined, eventId: string | undefined): IApp; static getLocalJitsiWrapperUrl(opts?: { forLocalRender?: boolean; auth?: string; }): string; static getWidgetName(app?: IWidget): string; static getWidgetDataTitle(app?: IWidget): string; static getWidgetUid(app?: IApp | IWidget): string; static calcWidgetUid(widgetId: string, roomId?: string): string; static editWidget(room: Room, app: IWidget): void; static isManagedByManager(app: IWidget): boolean; } /** * Hook to get the widgets for a room and update when they change * @param room the room to get widgets for */ export declare const useWidgets: (room: Room) => IApp[];