diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index 3c2ca181..abd46d49 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -499,12 +499,10 @@ export const RoomInput = forwardRef( // Cancel failed — leave state intact for retry } } else { - try { - await mx.sendMessage(roomId, content as any); - } catch (error) { - log.error('failed to send message', { roomId }, error); - } resetInput(); + mx.sendMessage(roomId, content as any).catch((error: unknown) => { + log.error('failed to send message', { roomId }, error); + }); } }, [ mx, diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index c153ab52..f9a652c5 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -1197,6 +1197,14 @@ export function RoomTimeline({ [mx, room] ); + const handleDeleteFailedSend = useCallback( + (mEvent: MatrixEvent) => { + if (mEvent.getAssociatedStatus() !== EventStatus.NOT_SENT) return; + mx.cancelPendingEvent(mEvent); + }, + [mx] + ); + const handleEdit = useCallback( (editEvtId?: string) => { if (editEvtId) { @@ -1269,6 +1277,7 @@ export function RoomTimeline({ senderDisplayName={senderDisplayName} sendStatus={mEvent.getAssociatedStatus()} onResend={handleResend} + onDeleteFailedSend={handleDeleteFailedSend} onEditId={handleEdit} activeReplyId={activeReplyId} reply={ @@ -1356,6 +1365,7 @@ export function RoomTimeline({ senderDisplayName={senderDisplayName} sendStatus={mEvent.getAssociatedStatus()} onResend={handleResend} + onDeleteFailedSend={handleDeleteFailedSend} reply={ replyEventId && ( void; + onDeleteFailedSend?: (event: MatrixEvent) => void; }; function useMobileDoubleTap(callback: () => void, delay = 300) { @@ -308,6 +309,7 @@ function MessageInternal( activeReplyId, sendStatus, onResend, + onDeleteFailedSend, ...props }: MessageProps & { className?: string; children?: ReactNode }, ref: any @@ -445,6 +447,7 @@ function MessageInternal( sendStatus === EventStatus.SENDING; const isFailedSend = sendStatus === EventStatus.NOT_SENT; const canResend = isFailedSend && senderId === mx.getUserId() && !!onResend; + const canDeleteFailedSend = isFailedSend && senderId === mx.getUserId() && !!onDeleteFailedSend; const handleResendClick: MouseEventHandler = useCallback( (evt) => { @@ -455,6 +458,15 @@ function MessageInternal( [mEvent, onResend] ); + const handleDeleteFailedSendClick: MouseEventHandler = useCallback( + (evt) => { + evt.preventDefault(); + evt.stopPropagation(); + onDeleteFailedSend?.(mEvent); + }, + [mEvent, onDeleteFailedSend] + ); + const MSG_CONTENT_STYLE = { maxWidth: '100%' }; const msgContentJSX = ( @@ -484,13 +496,6 @@ function MessageInternal( {children} )} {reactions} - {isPendingSend && ( - - - Sending... - - - )} {isFailedSend && ( @@ -501,6 +506,11 @@ function MessageInternal( Retry )} + {canDeleteFailedSend && ( + + )} )}