fix: improve message send UX

- Remove 'Sending...' text from pending messages; text is now dimmed via opacity while in-flight to reduce timeline jump
- Add 'Delete' button alongside 'Retry' on failed sends, using mx.cancelPendingEvent for client-side removal
- Clear the input box immediately on send rather than waiting for the network round-trip to complete
This commit is contained in:
Evie Gauthier committed 2026-03-04 19:45:53 -05:00
1 parent c38a927406
commit 2cf5b8382c
3 files changed
+31 -12

No files matched your search

+3 -5
View File
@@ -499,12 +499,10 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
// 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,
+11
View File
@@ -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 && (
<Reply
@@ -1474,6 +1484,7 @@ export function RoomTimeline({
senderDisplayName={senderDisplayName}
sendStatus={mEvent.getAssociatedStatus()}
onResend={handleResend}
onDeleteFailedSend={handleDeleteFailedSend}
reply={
replyEventId && (
<Reply
+17 -7
View File
@@ -227,6 +227,7 @@ export type MessageProps = {
activeReplyId?: string | null;
sendStatus?: EventStatus | null;
onResend?: (event: MatrixEvent) => 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<HTMLButtonElement> = useCallback(
(evt) => {
@@ -455,6 +458,15 @@ function MessageInternal(
[mEvent, onResend]
);
const handleDeleteFailedSendClick: MouseEventHandler<HTMLButtonElement> = useCallback(
(evt) => {
evt.preventDefault();
evt.stopPropagation();
onDeleteFailedSend?.(mEvent);
},
[mEvent, onDeleteFailedSend]
);
const MSG_CONTENT_STYLE = { maxWidth: '100%' };
const msgContentJSX = (
@@ -484,13 +496,6 @@ function MessageInternal(
<MemoizedBody key={stableContent}>{children}</MemoizedBody>
)}
{reactions}
{isPendingSend && (
<Box className={css.SendStatusRow}>
<Text size="T200" priority="300">
Sending...
</Text>
</Box>
)}
{isFailedSend && (
<Box className={css.SendStatusRow}>
<Text size="T200" priority="300">
@@ -501,6 +506,11 @@ function MessageInternal(
Retry
</button>
)}
{canDeleteFailedSend && (
<button type="button" className={css.SendStatusButton} onClick={handleDeleteFailedSendClick}>
Delete
</button>
)}
</Box>
)}
</Box>