refactor(DP15): centralize sendStateEvent as-any cast in typed helper

Add a typed `sendStateEvent(mx, roomId, eventType, content, stateKey?)`
helper in utils/room.ts that mirrors the DP16 account-data helper pattern.
The SDK's typed `sendStateEvent` overload rejects the fork's custom
`StateEvent` enum values, so every call site cast arg 2 to `any` (which
also collapsed the content type). The single `as any` cast now lives inside
the helper; a generic `content: T extends object` keeps each call site's
content type checked.

Route all 32 `mx.sendStateEvent(..., StateEvent.X as any, ...)` casts across
20 files through the helper. The 2 dynamic-string casts in developer-tools
(SendRoomEvent, StateEventEditor) pass a runtime string, not an enum value,
so they stay as-is.

No behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-07 23:32:50 -04:00
parent 4fc3f7a35f
commit 101e4116e8
21 changed files with 83 additions and 43 deletions
+8 -6
View File
@@ -24,7 +24,7 @@ import {
} from '../utils/matrix';
import { useRoomNavigate } from './useRoomNavigate';
import { Membership, StateEvent } from '../../types/matrix/room';
import { getStateEvent } from '../utils/room';
import { getStateEvent, sendStateEvent } from '../utils/room';
import { splitWithSpace } from '../utils/common';
import { createRoomEncryptionState } from '../components/create-room';
@@ -368,9 +368,10 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
?.getStateEvents(StateEvent.RoomMember, mx.getSafeUserId());
const content = mEvent?.getContent();
if (!content) return;
await mx.sendStateEvent(
await sendStateEvent(
mx,
room.roomId,
StateEvent.RoomMember as any,
StateEvent.RoomMember,
{
...content,
displayname: nick,
@@ -390,9 +391,10 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
?.getStateEvents(StateEvent.RoomMember, mx.getSafeUserId());
const content = mEvent?.getContent();
if (!content) return;
await mx.sendStateEvent(
await sendStateEvent(
mx,
room.roomId,
StateEvent.RoomMember as any,
StateEvent.RoomMember,
{
...content,
avatar_url: payload,
@@ -532,7 +534,7 @@ export const useCommands = (mx: MatrixClient, room: Room): CommandRecord => {
aclContent.allow?.sort();
aclContent.deny?.sort();
await mx.sendStateEvent(room.roomId, StateEvent.RoomServerAcl as any, aclContent);
await sendStateEvent(mx, room.roomId, StateEvent.RoomServerAcl, aclContent);
},
},
}),