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
@@ -1,10 +1,9 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import React, { KeyboardEvent, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Box, Chip, color, config, Icon, Icons, Text, toRem } from 'folds';
|
||||
import { RelationsEvent } from 'matrix-js-sdk/lib/models/relations';
|
||||
import { MatrixEvent, Room, RoomEvent, PollEvent } from 'matrix-js-sdk';
|
||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||
import { getMemberName } from '../../../utils/room';
|
||||
import { getMemberName, sendRoomEvent } from '../../../utils/room';
|
||||
import {
|
||||
ParsedPoll,
|
||||
PollResponse,
|
||||
@@ -220,7 +219,7 @@ export function PollContent({
|
||||
setPending(next);
|
||||
// Send the STABLE m.poll.response (matches Lotus's stable m.poll.start; the reader
|
||||
// accepts both namespaces).
|
||||
mx.sendEvent(roomId, 'm.poll.response' as any, {
|
||||
sendRoomEvent(mx, roomId, null, 'm.poll.response', {
|
||||
'm.relates_to': { rel_type: 'm.reference', event_id: eventId },
|
||||
'm.selections': Array.from(next),
|
||||
}).catch(() => setPending(null));
|
||||
@@ -229,7 +228,7 @@ export function PollContent({
|
||||
const handleEndPoll = () => {
|
||||
if (!roomId || !eventId || ending) return;
|
||||
setEnding(true);
|
||||
mx.sendEvent(roomId, 'm.poll.end' as any, {
|
||||
sendRoomEvent(mx, roomId, null, 'm.poll.end', {
|
||||
'm.relates_to': { rel_type: 'm.reference', event_id: eventId },
|
||||
'm.poll.end': {},
|
||||
'm.text': 'The poll has ended.',
|
||||
|
||||
Reference in New Issue
Block a user