mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-12-03 12:49:30 +00:00
09bbf796dc
* Add support for Widget & Room Header Buttons module APIs To support https://github.com/element-hq/element-modules/pull/217 * Update for new api * Test addRoomHeaderButtonCallback * Extra mock api * Test for widgetapi * Convert enum * Convert other enum usage * Add tests for widget context menu move buttons Which have just changed because of the enum * Add tests for moving the widgets * Fix copyright Co-authored-by: Florian Duros <florianduros@element.io> * Update module API * A little import/export --------- Co-authored-by: Florian Duros <florianduros@element.io>
48 lines
1.8 KiB
TypeScript
48 lines
1.8 KiB
TypeScript
/*
|
|
Copyright 2026 Element Creations Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import { type Container, type WidgetApi as WidgetApiInterface } from "@element-hq/element-web-module-api";
|
|
import { getHttpUriForMxc } from "matrix-js-sdk/src/matrix";
|
|
|
|
import type { IWidget } from "matrix-widget-api";
|
|
import WidgetStore, { isAppWidget } from "../stores/WidgetStore";
|
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
|
import { WidgetLayoutStore } from "../stores/widgets/WidgetLayoutStore";
|
|
|
|
/**
|
|
* Host-side implementation of the widget API.
|
|
* Allows modules to interact with widgets, including listing widgets in rooms.
|
|
*/
|
|
export class WidgetApi implements WidgetApiInterface {
|
|
public getWidgetsInRoom(roomId: string): IWidget[] {
|
|
return WidgetStore.instance.getApps(roomId);
|
|
}
|
|
|
|
public getAppAvatarUrl(app: IWidget, width?: number, height?: number, resizeMethod?: string): string | null {
|
|
if (!isAppWidget(app) || !app.avatar_url) return null;
|
|
return getHttpUriForMxc(
|
|
MatrixClientPeg.safeGet().getHomeserverUrl(),
|
|
app.avatar_url,
|
|
width,
|
|
height,
|
|
resizeMethod,
|
|
);
|
|
}
|
|
|
|
public isAppInContainer(app: IWidget, container: Container, roomId: string): boolean {
|
|
const room = MatrixClientPeg.safeGet().getRoom(roomId);
|
|
if (!room) return false;
|
|
return WidgetLayoutStore.instance.isInContainer(room, app, container);
|
|
}
|
|
|
|
public moveAppToContainer(app: IWidget, container: Container, roomId: string): void {
|
|
const room = MatrixClientPeg.safeGet().getRoom(roomId);
|
|
if (!room) return;
|
|
WidgetLayoutStore.instance.moveToContainer(room, app, container);
|
|
}
|
|
}
|