fix(composer): fix mobile edit regressions from refactoring

This commit is contained in:
Erwan Leboucher committed 2026-08-07 08:58:05 +02:00
1 parent 6a88b1a7b6
commit aa867dd09b
3 files changed
+30 -5

No files matched your search

+20
View File
@@ -1234,4 +1234,24 @@ describe('RoomInput submit regressions', () => {
);
expect(onCancelEdit).toHaveBeenCalledOnce();
});
it('sends a mobile edit as a replacement, not a reply, when a reply draft exists', async () => {
testState.isMobile = true;
testState.editingEvent = {
getId: () => '$original',
getContent: () => ({ body: 'original', msgtype: 'm.text' }),
};
const onCancelEdit = vi.fn();
render(<RoomInputHarness editId="$original" onCancelEdit={onCancelEdit} initialReply />);
await waitFor(() => expect(screen.getByTestId('room-input-editor')).toBeInTheDocument());
fireEvent.input(screen.getByTestId('room-input-editor'));
fireEvent.click(screen.getByRole('button', { name: 'Send your composed Message' }));
await waitFor(() => expect(testState.matrix.sendMessage).toHaveBeenCalledOnce());
const sentContent = testState.matrix.sendMessage.mock.calls[0]![1];
expect(sentContent['m.relates_to']).toEqual(expect.objectContaining({ rel_type: 'm.replace' }));
expect(sentContent['m.relates_to']).not.toHaveProperty('m.in_reply_to');
expect(onCancelEdit).toHaveBeenCalledOnce();
});
});
+6 -3
View File
@@ -1897,7 +1897,12 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
const content = await getGifMsgContent(mx, gif, url, spoiler);
if (!content) throw new Error('Unsendable GIF content');
return await handleSendContents({ contents: [content], submission, isLive });
const sent = await handleSendContents({ contents: [content], submission, isLive });
// When the editor has text, the reply is not attached to the GIF, so hand the
// claim back for the follow-up message to carry it.
if (sent && submission.replyClaim && toPlainText(submission.children).trim().length > 0)
restoreReplyClaim(submission.replyClaim);
return sent;
} catch (error) {
log.error('failed to send gif', { roomId }, error);
restoreReplyClaim(submission.replyClaim);
@@ -1906,8 +1911,6 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
});
};
if (isEditInitializing) return <div ref={ref} />;
return (
<div ref={ref}>
<Overlay
+4 -2
View File
@@ -101,6 +101,8 @@ export function RoomView({ eventId }: { eventId?: string }) {
alive,
focusOnCancel: !isMobileOrTablet(),
});
const onCancelEdit = useCallback(() => handleEdit(undefined), [handleEdit]);
const onEditLastMessage = useCallback(() => editLastMessageRef.current?.(), []);
useDelayedEventsSupport();
const delayedEventsSupported = useAtomValue(delayedEventsSupportedAtom);
@@ -194,9 +196,9 @@ export function RoomView({ eventId }: { eventId?: string }) {
roomId={roomId}
fileDropContainerRef={roomViewRef}
ref={roomInputRef}
onEditLastMessage={() => editLastMessageRef.current?.()}
onEditLastMessage={onEditLastMessage}
editId={editId}
onCancelEdit={() => handleEdit(undefined)}
onCancelEdit={onCancelEdit}
/>
)}
{!canMessage && (