mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-12-03 12:49:30 +00:00
91a3cb03c1
mkdir apps/web/scripts
mv scripts/{cleanup.sh,ci_package.sh,copy-res.ts,deploy.py,package.sh} apps/web/scripts
And a couple of gitignore tweaks
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
/*
|
|
Copyright 2025 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 { Watchable, type AccountDataApi as IAccountDataApi } from "@element-hq/element-web-module-api";
|
|
import { ClientEvent, type MatrixEvent, type MatrixClient } from "matrix-js-sdk/src/matrix";
|
|
|
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
|
|
|
export class AccountDataApi implements IAccountDataApi {
|
|
public get(eventType: string): Watchable<unknown> {
|
|
const cli = MatrixClientPeg.safeGet();
|
|
return new AccountDataWatchable(cli, eventType);
|
|
}
|
|
|
|
public async set(eventType: string, content: any): Promise<void> {
|
|
const cli = MatrixClientPeg.safeGet();
|
|
//@ts-expect-error: JS-SDK accepts known event-types, intentionally allow arbitrary types.
|
|
await cli.setAccountData(eventType, content);
|
|
}
|
|
|
|
public async delete(eventType: string): Promise<void> {
|
|
const cli = MatrixClientPeg.safeGet();
|
|
//@ts-expect-error: JS-SDK accepts known event-types, intentionally allow arbitrary types.
|
|
await cli.deleteAccountData(eventType);
|
|
}
|
|
}
|
|
|
|
class AccountDataWatchable extends Watchable<unknown> {
|
|
public constructor(
|
|
private cli: MatrixClient,
|
|
private eventType: string,
|
|
) {
|
|
//@ts-expect-error: JS-SDK accepts known event-types, intentionally allow arbitrary types.
|
|
super(cli.getAccountData(eventType)?.getContent());
|
|
}
|
|
|
|
private onAccountData = (event: MatrixEvent): void => {
|
|
if (event.getType() === this.eventType) {
|
|
this.value = event.getContent();
|
|
}
|
|
};
|
|
|
|
protected onFirstWatch(): void {
|
|
this.cli.on(ClientEvent.AccountData, this.onAccountData);
|
|
}
|
|
|
|
protected onLastWatch(): void {
|
|
this.cli.off(ClientEvent.AccountData, this.onAccountData);
|
|
}
|
|
}
|