refactor(types): typed send helpers replace 16 as any casts (#210)
- sendRoomMessage (composer's fire-and-forget sends: text, location, voice, files, GIFs) and sendRoomEvent (polls, poll responses/ends, forwards, reactions, edits) in utils/room.ts carry the one cast each needs (`keyof TimelineEvents` / `RoomMessageEventContent`, no `any`). - sendRoomMessage also swallows the rejected promise: a failed send already shows on the local echo (Failed to send + Retry, or the consent prompt), so it no longer surfaces as an unhandled error in the console. - getAccountData narrows to `keyof AccountDataEvents`; ForwardMessageDialog's guard now narrows `contentToSend` itself (same behaviour). - `as any` 39 → 23; eslint warnings 46 → 36, ratchet tightened to 36. Verified in Chromium on a local Synapse: a text message, a quick reaction and an edit all reach the server with the right content; a consent-blocked send no longer logs an unhandled MatrixError. 1219 unit tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
39589b40f3
commit
e39714a6e0
@@ -36,7 +36,12 @@ import { mxcUrlToHttp } from '../../../utils/matrix';
|
||||
import { RoomAvatar, RoomIcon } from '../../../components/room-avatar';
|
||||
import { UserAvatar } from '../../../components/user-avatar';
|
||||
import { ThumbnailContent } from '../../../components/message/content/ThumbnailContent';
|
||||
import { getMemberAvatarMxc, getMemberName, trimReplyFromBody } from '../../../utils/room';
|
||||
import {
|
||||
getMemberAvatarMxc,
|
||||
getMemberName,
|
||||
sendRoomEvent,
|
||||
trimReplyFromBody,
|
||||
} from '../../../utils/room';
|
||||
import { nameInitials } from '../../../utils/common';
|
||||
import {
|
||||
recentForwardTargetsAtom,
|
||||
@@ -349,12 +354,12 @@ export function ForwardMessageDialog({ mEvent, onClose }: Props) {
|
||||
// content; unencrypted ones get the plaintext version, or fail outright if
|
||||
// that couldn't be built — never fall back to sending the encrypted `file`.
|
||||
const contentToSend = fwdContent.file && !destEncrypted ? plaintextContent : fwdContent;
|
||||
if (fwdContent.file && !destEncrypted && !contentToSend) {
|
||||
// Only undefined when a plaintext copy was needed and couldn't be built.
|
||||
if (!contentToSend) {
|
||||
return Promise.reject(new Error(plaintextContentError));
|
||||
}
|
||||
// threadId-aware overload (P3-8): explicit null = send to the main timeline.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const sendForward = () => mx.sendEvent(id, null, mEvent.getType() as any, contentToSend);
|
||||
// Explicit null thread = send to the main timeline.
|
||||
const sendForward = () => sendRoomEvent(mx, id, null, mEvent.getType(), contentToSend);
|
||||
// Send the optional comment first so it reads as a note above the
|
||||
// forwarded content. The room counts as failed if either send rejects.
|
||||
// Track rooms whose comment already landed so a retry (after the FORWARD
|
||||
|
||||
@@ -21,7 +21,15 @@ import {
|
||||
} from 'folds';
|
||||
import { Editor, Transforms } from 'slate';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { IContent, IMentions, MatrixEvent, MsgType, RelationType, Room } from 'matrix-js-sdk';
|
||||
import {
|
||||
EventType,
|
||||
IContent,
|
||||
IMentions,
|
||||
MatrixEvent,
|
||||
MsgType,
|
||||
RelationType,
|
||||
Room,
|
||||
} from 'matrix-js-sdk';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import {
|
||||
AUTOCOMPLETE_PREFIXES,
|
||||
@@ -55,6 +63,7 @@ import {
|
||||
getEditedEvent,
|
||||
getMemberName,
|
||||
getMentionContent,
|
||||
sendRoomEvent,
|
||||
trimReplyFromFormattedBody,
|
||||
} from '../../../utils/room';
|
||||
import { mobileOrTablet } from '../../../utils/user-agent';
|
||||
@@ -192,8 +201,7 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
rel_type: RelationType.Replace,
|
||||
},
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return mx.sendMessage(roomId, content as any);
|
||||
return sendRoomEvent(mx, roomId, null, EventType.RoomMessage, content);
|
||||
}
|
||||
|
||||
const [prevBody, prevCustomHtml, prevMentions] = getPrevBodyAndFormattedBody();
|
||||
@@ -241,8 +249,7 @@ export const MessageEditor = as<'div', MessageEditorProps>(
|
||||
},
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return mx.sendMessage(roomId, content as any);
|
||||
return sendRoomEvent(mx, roomId, null, EventType.RoomMessage, content);
|
||||
}, [
|
||||
stripTracking,
|
||||
mx,
|
||||
|
||||
Reference in New Issue
Block a user