Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/mobile/src/components/ComposerAttachmentStrip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ function ComposerFileAttachment(
const canPreview = isPdfFile(attachment) && props.onPressPreview !== undefined;
const sourceIdentifier = `draft-file:${attachment.id}`;
const onPressDocument = props.onPressDocument;
const upload = useComposerAttachmentUploadState(props.environmentId, attachment.id);
const showsUploadBadge = upload !== undefined && upload.status !== "ready";
return (
<>
<PresentationSource identifier={sourceIdentifier}>
Expand All @@ -220,7 +222,7 @@ function ComposerFileAttachment(
className={
props.compact
? "items-center justify-center bg-subtle"
: "items-center justify-center gap-1 bg-subtle px-2"
: `items-center justify-center gap-1 bg-subtle px-2${showsUploadBadge ? " pb-4" : ""}`
}
style={style}
>
Expand Down
8 changes: 7 additions & 1 deletion apps/mobile/src/features/threads/ThreadComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import {
composerStripAttachments,
type DraftComposerFileAttachment,
} from "../../lib/composerImages";
import { composerAttachmentUploadKey } from "../../lib/composerAttachmentUploadQueue";
import {
buildModelOptions,
isModelSelectionUnavailable,
Expand Down Expand Up @@ -474,7 +475,6 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
draftMessage.trim().length > 0 ||
draftAttachments.length > 0 ||
(queuedEdit?.existingAttachments.length ?? 0) > 0;
const stripAttachments = composerStripAttachments(draftAttachments);
const showStopAction = !hasContent && props.canStopThread && queuedEdit === null;
const onResumeQueue = props.onResumeQueue;
const [resumingQueue, setResumingQueue] = useState(false);
Expand All @@ -492,6 +492,12 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
AuthOrchestrationOperateScope,
);
const uploadStates = useAtomValue(composerAttachmentUploadsAtom);
const stripAttachments = composerStripAttachments(
draftAttachments,
(attachment) =>
uploadStates[composerAttachmentUploadKey(props.environmentId, attachment.id)]?.status ===
"failed",
);
const attachmentsUploading =
props.connectionState === "connected" &&
composerAttachmentsStillUploading({
Expand Down
16 changes: 11 additions & 5 deletions apps/mobile/src/lib/composerImages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,16 @@ describe("composerStripAttachments", () => {

it("keeps media beside a document rather than dropping the whole strip", async () => {
const { composerStripAttachments } = await import("./composerImages");
expect(composerStripAttachments([doc, image, video] as never).map((a) => a.id)).toEqual([
"img-1",
"vid-1",
]);
expect(
composerStripAttachments([doc, image, video] as never, () => false).map((a) => a.id),
).toEqual(["img-1", "vid-1"]);
});

it("shows a document whose upload failed, so it can be retried", async () => {
const { composerStripAttachments } = await import("./composerImages");
expect(
composerStripAttachments([doc, image] as never, (a) => a.id === "doc-1").map((a) => a.id),
).toEqual(["doc-1", "img-1"]);
});

it("keeps oversized document-picked images visible while sending them as files", async () => {
Expand All @@ -350,7 +356,7 @@ describe("composerStripAttachments", () => {
sizeBytes: PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1,
};

expect(composerStripAttachments([oversizedImage])).toEqual([oversizedImage]);
expect(composerStripAttachments([oversizedImage], () => false)).toEqual([oversizedImage]);
expect(isComposerImageAttachment(oversizedImage)).toBe(false);
});
});
9 changes: 7 additions & 2 deletions apps/mobile/src/lib/composerImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,20 @@ export async function createPastedTextComposerAttachment(input: {

export type DraftComposerAttachment = DraftComposerImageAttachment | DraftComposerFileAttachment;

/** Non-media attachments require chip references; missing references mean lost draft files. */
/**
* Non-media attachments require chip references; missing references mean lost draft files.
* A chip cannot retry an upload, so a document whose upload failed joins the strip.
*/
export function composerStripAttachments(
attachments: ReadonlyArray<DraftComposerAttachment>,
uploadFailed: (attachment: DraftComposerAttachment) => boolean,
): ReadonlyArray<DraftComposerAttachment> {
return attachments.filter(
(attachment) =>
attachment.type === "image" ||
imageMimeType(attachment) !== null ||
videoMimeType(attachment) !== null,
videoMimeType(attachment) !== null ||
uploadFailed(attachment),
);
}

Expand Down