fix(composer): fix mobile edit regressions from refactoring (#1657)

<!-- Please read
https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before
submitting your pull request -->

### Description

<!-- Please include a summary of the change. Please also include
relevant motivation and context. List any dependencies that are required
for this change. -->

Fixes #

#### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings

### AI disclosure:

- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [ ] Fully AI generated (explain what all the generated code does in
moderate detail).
<!-- Write any explanation required here, but do not generate the
explanation using AI!! You must prove you understand what the code in
this PR does. -->
This commit is contained in:
Erwan Leboucher authored and GitHub committed 2026-08-07 07:00:43 +00:00
commit fb6074c920
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 && (