diff --git a/src/app/features/room/RoomInput.test.tsx b/src/app/features/room/RoomInput.test.tsx
index f61c9674c..62f1681b0 100644
--- a/src/app/features/room/RoomInput.test.tsx
+++ b/src/app/features/room/RoomInput.test.tsx
@@ -781,6 +781,28 @@ describe('RoomInput submit regressions', () => {
);
});
+ it('sends a replied attachment once when a touch produces pointerup and click', async () => {
+ const send = deferred<{ event_id: string }>();
+ const file = new File(['attachment'], 'attachment.txt', { type: 'text/plain' });
+ testState.isMobile = true;
+ testState.sendIndividualAttachmentAsCaption = true;
+ testState.pendingUploads = [{ status: 'success', file, mxc: 'mxc://example/attachment' }];
+ testState.matrix.sendMessage.mockReturnValue(send.promise);
+ render();
+ fireEvent.click(screen.getByRole('button', { name: 'Prepare attachment' }));
+
+ const submit = sendButton();
+ fireEvent.pointerDown(submit, { pointerType: 'touch' });
+ fireEvent.pointerUp(submit, { pointerType: 'touch' });
+ fireEvent.click(submit);
+
+ await waitFor(() => expect(testState.matrix.sendMessage).toHaveBeenCalledOnce());
+ expect(testState.matrix.sendMessage.mock.calls[0]?.[2]?.['m.relates_to']).toEqual(
+ expect.objectContaining({ 'm.in_reply_to': expect.anything() })
+ );
+ send.resolve({ event_id: '$event' });
+ });
+
it('sends on touch pointerup when the tap never produces a click', async () => {
render();
fireEvent.click(screen.getByRole('button', { name: 'Compose text' }));
diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx
index fbc7f028c..e2eb87450 100644
--- a/src/app/features/room/RoomInput.tsx
+++ b/src/app/features/room/RoomInput.tsx
@@ -393,6 +393,7 @@ export const RoomInput = forwardRef(
const [isSending, setIsSending] = useState(false);
const [ingestingFiles, setIngestingFiles] = useState(false);
const fileIngestionCountRef = useRef(0);
+ const submissionInFlightRef = useRef(false);
const composerControllerRef = useRef();
composerControllerRef.current ??= createComposerController();
// Bumped when this composer goes away, so async work started for a previous
@@ -1714,16 +1715,20 @@ export const RoomInput = forwardRef(
);
const submit = useCallback(() => {
+ if (submissionInFlightRef.current) return Promise.resolve(undefined);
+ submissionInFlightRef.current = true;
// A mobile edit replaces an existing event, so it owns neither the draft nor the reply.
const isMobileEdit = Boolean(editingEvent && isMobile);
const submission = takeSubmission({
clearEditor: !isMobileEdit,
claimReplyDraft: !isMobileEdit,
});
- return (
+ const queued =
composerControllerRef.current?.enqueue((isLive) => executeSubmit(submission, isLive)) ??
- Promise.resolve(undefined)
- );
+ Promise.resolve(undefined);
+ return queued.finally(() => {
+ submissionInFlightRef.current = false;
+ });
}, [editingEvent, executeSubmit, isMobile, takeSubmission]);
const handleKeyDown: KeyboardEventHandler = useCallback(
diff --git a/src/app/features/room/nativeFilePicker.test.ts b/src/app/features/room/nativeFilePicker.test.ts
index 46938f7d6..ad0b1bfa5 100644
--- a/src/app/features/room/nativeFilePicker.test.ts
+++ b/src/app/features/room/nativeFilePicker.test.ts
@@ -170,6 +170,24 @@ describe('pickNativeFile', () => {
]);
});
+ it('does not return the same gallery URI twice', async () => {
+ const uri = androidUri('content://media/external/images/media/1000000034');
+ mocks.androidFs.showOpenFilePicker.mockResolvedValue([uri, uri]);
+ mocks.androidFs.getMetadata.mockResolvedValue({
+ type: 'File',
+ name: '1000000034.png',
+ lastModified: new Date(1700000000000),
+ byteLength: 3,
+ mimeType: 'image/png',
+ });
+
+ const files = await pickNativeFile('media');
+
+ expect(files).toHaveLength(1);
+ expect(mocks.androidFs.getMetadata).toHaveBeenCalledOnce();
+ expect(mocks.androidFs.readFile).toHaveBeenCalledOnce();
+ });
+
it('picks documents through the file picker', async () => {
mocks.androidFs.showOpenFilePicker.mockResolvedValue([androidUri('content://docs/1')]);
mocks.androidFs.getMetadata.mockResolvedValue({
diff --git a/src/app/features/room/nativeFilePicker.ts b/src/app/features/room/nativeFilePicker.ts
index 93ba65176..367eed28c 100644
--- a/src/app/features/room/nativeFilePicker.ts
+++ b/src/app/features/room/nativeFilePicker.ts
@@ -88,9 +88,15 @@ const pickAndroidFiles = async (
mimeTypes: pickerMode === 'media' ? MEDIA_MIME_TYPES : [],
multiple: true,
});
+ const seenUris = new Set();
+ const uniqueUris = uris.filter(({ uri }) => {
+ if (seenUris.has(uri)) return false;
+ seenUris.add(uri);
+ return true;
+ });
const files = await Promise.all(
- uris.map(async (uri, index): Promise => {
+ uniqueUris.map(async (uri, index): Promise => {
try {
const metadata = await AndroidFs.getMetadata(uri);
if (metadata.type !== 'File') return undefined;
diff --git a/src/app/utils/matrix.test.ts b/src/app/utils/matrix.test.ts
index 213410446..bbdf8fdf9 100644
--- a/src/app/utils/matrix.test.ts
+++ b/src/app/utils/matrix.test.ts
@@ -13,10 +13,15 @@ const mediaTransport = vi.hoisted(() => ({
getCurrentMediaSessionScope: vi.fn<() => string>(() => '@user:example.com'),
}));
+const reactions = vi.hoisted(() => ({
+ getEventReactions: vi.fn<() => unknown>(),
+}));
+
vi.mock('@tauri-apps/api/core', () => tauriApi);
vi.mock('./mediaTransport', () => mediaTransport);
+vi.mock('./room/relations', () => reactions);
-const { mxcUrlToHttp, rewriteAuthenticatedMediaUrl } = await import('./matrix');
+const { mxcUrlToHttp, rewriteAuthenticatedMediaUrl, toggleReaction } = await import('./matrix');
describe('rewriteAuthenticatedMediaUrl', () => {
beforeEach(() => {
@@ -101,6 +106,32 @@ describe('rewriteAuthenticatedMediaUrl', () => {
});
});
+describe('toggleReaction', () => {
+ it('redacts the existing reaction from the current user', () => {
+ const reaction = {
+ getId: () => '$reaction',
+ getSender: () => '@me:example.org',
+ };
+ reactions.getEventReactions.mockReturnValue({
+ getSortedAnnotationsByKey: () => [['👍', new Set([reaction])]],
+ });
+ const mx = {
+ getUserId: () => '@me:example.org',
+ redactEvent: vi.fn<(roomId: string, eventId: string) => void>(),
+ sendEvent: vi.fn<(...args: unknown[]) => void>(),
+ } as unknown as MatrixClient;
+ const room = {
+ roomId: '!room:example.org',
+ getUnfilteredTimelineSet: vi.fn<() => unknown>(),
+ };
+
+ toggleReaction(mx, room as never, '$message', '👍');
+
+ expect(mx.redactEvent).toHaveBeenCalledWith('!room:example.org', '$reaction');
+ expect(mx.sendEvent).not.toHaveBeenCalled();
+ });
+});
+
describe('mxcUrlToHttp', () => {
it('rewrites SDK legacy media URLs under Tauri without useAuthentication', () => {
tauriApi.isTauri.mockReturnValue(true);
diff --git a/src/app/utils/matrix.ts b/src/app/utils/matrix.ts
index 09e0f9f98..a585214b4 100644
--- a/src/app/utils/matrix.ts
+++ b/src/app/utils/matrix.ts
@@ -544,7 +544,7 @@ export const toggleReaction = (
const reactions: MatrixEvent[] = reactionsSet ? Array.from(reactionsSet) : [];
const myReaction = reactions.find(factoryEventSentBy(mx.getUserId()!));
- if (myReaction && myReaction.isRelation?.()) {
+ if (myReaction) {
const eventId = myReaction.getId();
if (eventId) mx.redactEvent(room.roomId, eventId);
return;