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:
2026-07-07 23:14:35 -04:00
co-authored by Claude Opus 4.8
parent e545706c3b
commit b1ee3ada98
16 changed files with 69 additions and 46 deletions
@@ -1,4 +1,4 @@
import { MatrixEvent, Room } from 'matrix-js-sdk';
import { Room } from 'matrix-js-sdk';
import React, { MouseEventHandler, useCallback, useEffect, useMemo, useState } from 'react';
import {
Box,
@@ -41,6 +41,7 @@ import {
import { LineClamp2 } from '../../../styles/Text.css';
import { allRoomsAtom } from '../../../state/room-list/roomList';
import { AccountDataEvent } from '../../../../types/matrix/accountData';
import { getAccountData, setAccountData } from '../../../utils/accountData';
import { AsyncStatus, useAsyncCallback } from '../../../hooks/useAsyncCallback';
import { stopPropagation } from '../../../utils/keyboard';
@@ -303,9 +304,7 @@ export function GlobalPacks({ onViewPack }: GlobalPacksProps) {
const [applyState, applyChanges] = useAsyncCallback(
useCallback(async () => {
const content =
(
(mx as any).getAccountData(AccountDataEvent.PoniesEmoteRooms) as MatrixEvent | undefined
)?.getContent<EmoteRoomsContent>() ?? {};
getAccountData<EmoteRoomsContent>(mx, AccountDataEvent.PoniesEmoteRooms) ?? {};
const updatedContent: EmoteRoomsContent = JSON.parse(JSON.stringify(content));
selectedPacks.forEach((addr) => {
@@ -322,7 +321,7 @@ export function GlobalPacks({ onViewPack }: GlobalPacksProps) {
}
});
await (mx as any).setAccountData(AccountDataEvent.PoniesEmoteRooms, updatedContent);
await setAccountData(mx, AccountDataEvent.PoniesEmoteRooms, updatedContent);
}, [mx, selectedPacks, removedPacks]),
);