DP16: add typed get/setAccountData helpers, remove ~19 any-casts
Add centralized typed helpers in src/app/utils/accountData.ts: - getAccountData<T>(mx, eventType): T | undefined (returns content) - setAccountData<T>(mx, eventType, content): Promise<void> These wrap the single `as any` cast needed because matrix-js-sdk's typed overloads reject the fork's custom account-data event names. Every call site now stays fully typed on its content shape. Route all account-data reads/writes that previously used `(mx as any).getAccountData/setAccountData` or `mx.getAccountData(... as any)` through the helpers (or, where a MatrixEvent is needed, through the existing utils/room.ts getAccountData whose param is widened to accept string keys). No behavior change: same event types, same content shapes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
} from '../utils/threadNotifications';
|
||||
import { useMatrixClient } from './useMatrixClient';
|
||||
import { AsyncState, useAsyncCallback } from './useAsyncCallback';
|
||||
import { getAccountData, setAccountData } from '../utils/accountData';
|
||||
|
||||
/** Read the current notification mode for a thread from the bound atom. */
|
||||
export function useThreadNotificationMode(
|
||||
@@ -23,9 +24,7 @@ export function useThreadNotificationMode(
|
||||
}
|
||||
|
||||
const readContent = (mx: MatrixClient): ThreadNotificationsContent =>
|
||||
((mx as any).getAccountData(AccountDataEvent.LotusThreadNotifications)?.getContent() as
|
||||
| ThreadNotificationsContent
|
||||
| undefined) ?? {};
|
||||
getAccountData<ThreadNotificationsContent>(mx, AccountDataEvent.LotusThreadNotifications) ?? {};
|
||||
|
||||
const getJoinedRoomIds = (mx: MatrixClient): Set<string> => {
|
||||
const joined = new Set<string>();
|
||||
@@ -74,7 +73,7 @@ const writeThreadNotificationMode = async (
|
||||
// ALWAYS prune before persisting to keep account data bounded.
|
||||
const finalContent = pruneThreadNotifications(next, getJoinedRoomIds(mx), now);
|
||||
|
||||
await (mx as any).setAccountData(AccountDataEvent.LotusThreadNotifications, finalContent);
|
||||
await setAccountData(mx, AccountDataEvent.LotusThreadNotifications, finalContent);
|
||||
};
|
||||
|
||||
export function useSetThreadNotificationMode(
|
||||
|
||||
Reference in New Issue
Block a user