Expose apps/widgets (#12071)

* Expose apps/widgets

Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net>

* Bump @matrix-org/react-sdk-module-api from 2.2.1 to 2.3.0

Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net>

---------

Signed-off-by: Charly Nguyen <charly.nguyen@nordeck.net>
This commit is contained in:
Charly Nguyen 2024-01-22 11:53:27 +01:00 committed by GitHub
parent 783007bea6
commit 11096b207a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 158 additions and 6 deletions

View file

@ -38,6 +38,8 @@ import { Action } from "../dispatcher/actions";
import { OverwriteLoginPayload } from "../dispatcher/payloads/OverwriteLoginPayload";
import { ActionPayload } from "../dispatcher/payloads";
import SettingsStore from "../settings/SettingsStore";
import WidgetStore, { IApp } from "../stores/WidgetStore";
import { Container, WidgetLayoutStore } from "../stores/widgets/WidgetLayoutStore";
/**
* Glue between the `ModuleApi` interface and the react-sdk. Anticipates one instance
@ -218,4 +220,38 @@ export class ProxiedModuleApi implements ModuleApi {
if (!maybeObj || !(typeof maybeObj === "object")) return undefined;
return maybeObj[key];
}
/**
* @override
*/
public getApps(roomId: string): IApp[] {
return WidgetStore.instance.getApps(roomId);
}
/**
* @override
*/
public getAppAvatarUrl(app: IApp, width?: number, height?: number, resizeMethod?: string): string | null {
if (!app.avatar_url) return null;
// eslint-disable-next-line no-restricted-properties
return MatrixClientPeg.safeGet().mxcUrlToHttp(app.avatar_url, width, height, resizeMethod);
}
/**
* @override
*/
public isAppInContainer(app: IApp, container: Container, roomId: string): boolean {
const room = MatrixClientPeg.safeGet().getRoom(roomId);
if (!room) return false;
return WidgetLayoutStore.instance.isInContainer(room, app, container);
}
/**
* @override
*/
public moveAppToContainer(app: IApp, container: Container, roomId: string): void {
const room = MatrixClientPeg.safeGet().getRoom(roomId);
if (!room) return;
WidgetLayoutStore.instance.moveToContainer(room, app, container);
}
}