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:
@@ -6,7 +6,7 @@ import { useMatrixClient } from './useMatrixClient';
|
||||
import { useAlive } from './useAlive';
|
||||
import { useStateEvent } from './useStateEvent';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
import { getStateEvent } from '../utils/room';
|
||||
import { getStateEvent, sendStateEvent } from '../utils/room';
|
||||
|
||||
export const usePublishedAliases = (room: Room): [string | undefined, string[]] => {
|
||||
const aliasContent = useStateEvent(
|
||||
@@ -56,7 +56,7 @@ export const useSetMainAlias = (room: Room): ((alias: string | undefined) => Pro
|
||||
alt_aliases: altAliases,
|
||||
};
|
||||
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomCanonicalAlias as any, newContent);
|
||||
await sendStateEvent(mx, room.roomId, StateEvent.RoomCanonicalAlias, newContent);
|
||||
},
|
||||
[mx, room],
|
||||
);
|
||||
@@ -90,7 +90,7 @@ export const usePublishUnpublishAliases = (
|
||||
alt_aliases: altAliases,
|
||||
};
|
||||
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomCanonicalAlias as any, newContent);
|
||||
await sendStateEvent(mx, room.roomId, StateEvent.RoomCanonicalAlias, newContent);
|
||||
},
|
||||
[mx, room],
|
||||
);
|
||||
@@ -114,7 +114,7 @@ export const usePublishUnpublishAliases = (
|
||||
alt_aliases: altAliases,
|
||||
};
|
||||
|
||||
await mx.sendStateEvent(room.roomId, StateEvent.RoomCanonicalAlias as any, newContent);
|
||||
await sendStateEvent(mx, room.roomId, StateEvent.RoomCanonicalAlias, newContent);
|
||||
},
|
||||
[mx, room],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user