Skip to content

Commit 55b6036

Browse files
committed
fix(mobile): allow sending attachments after draft save failures
1 parent 16918b5 commit 55b6036

4 files changed

Lines changed: 481 additions & 3 deletions

File tree

‎apps/mobile/src/lib/composerAttachmentUploadQueue.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,42 @@ describe("composer attachment upload queue", () => {
244244
expect(upload).toHaveBeenCalledOnce();
245245
queue.dispose();
246246
});
247+
248+
it("keeps other upload failures blocking alongside a failure recoverable on Send", async () => {
249+
const persistenceFailure = new Error("Draft storage unavailable");
250+
const requests = [request("draft"), request("network")];
251+
let states: Readonly<Record<string, ComposerAttachmentUploadState>> = {};
252+
const queue = createComposerAttachmentUploadQueue({
253+
upload: async ({ attachment }) => {
254+
throw attachment.id === "draft" ? persistenceFailure : new Error("Network unavailable");
255+
},
256+
canQueueOnSend: (error) => error === persistenceFailure,
257+
onChange: (next) => {
258+
states = next;
259+
},
260+
});
261+
queue.sync(requests);
262+
await queue.settled();
263+
const input = {
264+
environmentId,
265+
attachments: requests.map(({ attachment }) => attachment),
266+
connected: true,
267+
serverConfig: {
268+
environment: {
269+
capabilities: { attachmentUploads: true, fileAttachments: { maxUploadBytes: 1024 } },
270+
},
271+
},
272+
states,
273+
};
274+
expect(composerAttachmentUploadBlockReason(input)).toBe(
275+
"Retry or remove the failed attachment",
276+
);
277+
expect(composerAttachmentsStillUploading(input)).toBe(true);
278+
const recoverable = { ...input, attachments: [requests[0]!.attachment] };
279+
expect(composerAttachmentUploadBlockReason(recoverable)).toBeNull();
280+
expect(composerAttachmentsStillUploading(recoverable)).toBe(true);
281+
queue.dispose();
282+
});
247283
});
248284

249285
describe("draft upload scope and offline submission", () => {

‎apps/mobile/src/lib/composerAttachmentUploadQueue.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ComposerAttachmentUploadRequest {
1212
export type ComposerAttachmentUploadState =
1313
| { readonly status: "uploading"; readonly progress: number }
1414
| { readonly status: "ready" }
15-
| { readonly status: "failed"; readonly reason: string };
15+
| { readonly status: "failed"; readonly reason: string; readonly queueOnSend?: boolean };
1616

1717
export function composerAttachmentUploadKey(
1818
environmentId: EnvironmentId,
@@ -80,7 +80,8 @@ export function composerAttachmentUploadBlockReason(input: {
8080
for (const attachment of input.attachments) {
8181
if (!canUploadComposerAttachment(attachment, input.serverConfig)) continue;
8282
const state = input.states[composerAttachmentUploadKey(input.environmentId, attachment.id)];
83-
if (state?.status === "failed") return "Retry or remove the failed attachment";
83+
if (state?.status === "failed" && !state.queueOnSend)
84+
return "Retry or remove the failed attachment";
8485
}
8586
return null;
8687
}
@@ -94,7 +95,7 @@ export function composerAttachmentsStillUploading(input: {
9495
return input.attachments.some((attachment) => {
9596
if (!canUploadComposerAttachment(attachment, input.serverConfig)) return false;
9697
const state = input.states[composerAttachmentUploadKey(input.environmentId, attachment.id)];
97-
return state?.status !== "ready" && state?.status !== "failed";
98+
return state?.status === "failed" ? state.queueOnSend === true : state?.status !== "ready";
9899
});
99100
}
100101

@@ -104,6 +105,7 @@ export function createComposerAttachmentUploadQueue(options: {
104105
signal: AbortSignal,
105106
onProgress: (progress: number) => void,
106107
) => Promise<boolean>;
108+
readonly canQueueOnSend?: (error: unknown) => boolean;
107109
readonly onChange: (states: Readonly<Record<string, ComposerAttachmentUploadState>>) => void;
108110
}) {
109111
const jobs = new Map<
@@ -160,6 +162,7 @@ export function createComposerAttachmentUploadQueue(options: {
160162
setState(key, {
161163
status: "failed",
162164
reason: error instanceof Error ? error.message : "Upload failed. Tap to retry.",
165+
...(options.canQueueOnSend?.(error) ? { queueOnSend: true } : {}),
163166
});
164167
}
165168
})

0 commit comments

Comments
 (0)