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:
@@ -35,6 +35,7 @@ import { mxcUrlToHttp } from '../../../utils/matrix';
|
||||
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
|
||||
import { usePowerLevels } from '../../../hooks/usePowerLevels';
|
||||
import { StateEvent } from '../../../../types/matrix/room';
|
||||
import { sendStateEvent } from '../../../utils/room';
|
||||
import { suffixRename } from '../../../utils/common';
|
||||
import { AsyncStatus, useAsyncCallback } from '../../../hooks/useAsyncCallback';
|
||||
import { useAlive } from '../../../hooks/useAlive';
|
||||
@@ -57,7 +58,7 @@ function CreatePackTile({ packs, roomId }: CreatePackTileProps) {
|
||||
display_name: name,
|
||||
},
|
||||
};
|
||||
await mx.sendStateEvent(roomId, StateEvent.PoniesRoomEmotes as any, content, stateKey);
|
||||
await sendStateEvent(mx, roomId, StateEvent.PoniesRoomEmotes, content, stateKey);
|
||||
},
|
||||
[mx, roomId],
|
||||
),
|
||||
@@ -164,7 +165,7 @@ export function RoomPacks({ onViewPack }: RoomPacksProps) {
|
||||
for (let i = 0; i < removedPacks.length; i += 1) {
|
||||
const addr = removedPacks[i];
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.PoniesRoomEmotes as any, {}, addr.stateKey);
|
||||
await sendStateEvent(mx, room.roomId, StateEvent.PoniesRoomEmotes, {}, addr.stateKey);
|
||||
}
|
||||
}, [mx, room, removedPacks]),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user