Files
cinny/src/app/utils/accountData.ts
T
nathan 0656e6ecb0
CI / Build & Quality Checks (pull_request) Canceled after 0s
CI / Trigger Desktop Build (pull_request) Canceled after 0s
removed eslint unused ignore lines, config handles ignoring it now
2026-08-02 20:55:42 -04:00

27 lines
1013 B
TypeScript

import { MatrixClient, MatrixEvent } from 'matrix-js-sdk';
import { AccountDataEvent } from '../../types/matrix/accountData';
// Typed global account-data read/write helpers.
//
// matrix-js-sdk's `getAccountData`/`setAccountData` overloads only accept the
// SDK's built-in AccountDataEvents union and reject the fork's custom event
// names (the `io.lotus.*` / `in.cinny.*` values in the AccountDataEvent enum, as
// well as a few dynamic keys used by developer tools). We centralize the single
// `as any` cast here so every call site stays fully typed on its content shape.
export function getAccountData<T>(
mx: MatrixClient,
eventType: AccountDataEvent | string,
): T | undefined {
const event = (mx as any).getAccountData(eventType) as MatrixEvent | undefined;
return event?.getContent() as T | undefined;
}
export function setAccountData<T>(
mx: MatrixClient,
eventType: AccountDataEvent | string,
content: T,
): Promise<void> {
return (mx as any).setAccountData(eventType, content);
}