diff --git a/src/app/features/room/RoomInput.test.tsx b/src/app/features/room/RoomInput.test.tsx index d4807fb6c..517db52c6 100644 --- a/src/app/features/room/RoomInput.test.tsx +++ b/src/app/features/room/RoomInput.test.tsx @@ -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(); + + 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(); + }); }); diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index c5b24b971..8bb444479 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -1897,7 +1897,12 @@ export const RoomInput = forwardRef( 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( }); }; - if (isEditInitializing) return
; - return (
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 && (