Skip to content

Commit e48912e

Browse files
PR Batch Testerclaude
andcommitted
fix(mobile): only repair chips for share imports
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a68615c commit e48912e

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎apps/mobile/src/state/use-composer-drafts.test.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,13 +2318,15 @@ describe("mobile composer drafts", () => {
23182318
fileUri: "file:///documents/backup.json",
23192319
};
23202320

2321-
const merged = mergeComposerDraftContentState({}, draftKey, {
2322-
text: "",
2323-
attachments: [sharedFile],
2324-
sourceShareId: "share-1",
2325-
})[draftKey]!;
2321+
const existingFile = { ...sharedFile, id: "existing-file", name: "notes.txt" };
2322+
2323+
const merged = mergeComposerDraftContentState(
2324+
{ [draftKey]: { text: "", attachments: [existingFile] } },
2325+
draftKey,
2326+
{ text: "", attachments: [sharedFile], sourceShareId: "share-1" },
2327+
)[draftKey]!;
23262328

2327-
expect(merged.attachments).toEqual([sharedFile]);
2329+
expect(merged.attachments).toEqual([existingFile, sharedFile]);
23282330
const references = collectComposerContextReferences(merged.text);
23292331
expect(references).toHaveLength(1);
23302332
expect(merged.context?.records).toEqual([
@@ -2334,6 +2336,13 @@ describe("mobile composer drafts", () => {
23342336
attachmentId: sharedFile.id,
23352337
}),
23362338
]);
2339+
2340+
// A recovery merge carries its own text; a chip appended to it would
2341+
// break the duplicate-text check when the merge is retried.
2342+
const recovered = { text: "Retry this", attachments: [sharedFile] };
2343+
const once = mergeComposerDraftContentState({}, draftKey, recovered);
2344+
expect(once[draftKey]?.text).toBe("Retry this");
2345+
expect(mergeComposerDraftContentState(once, draftKey, recovered)).toBe(once);
23372346
});
23382347

23392348
it("preserves existing images when shared content exceeds the draft attachment limit", () => {

‎apps/mobile/src/state/use-composer-drafts.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,9 @@ export function mergeComposerDraftContentState(
15821582
return {
15831583
...current,
15841584
// The composer shows non-image files only as inline chips, so a shared file
1585-
// merged without one would be attached but invisible until sent.
1585+
// merged without one would be attached but invisible until sent. Other
1586+
// merges carry their own text, and appending chips to it would defeat
1587+
// mergeComposerDraftText's duplicate check on a retried merge.
15861588
[draftKey]: restoreMissingComposerFileReferences(
15871589
{
15881590
...existing,
@@ -1591,7 +1593,7 @@ export function mergeComposerDraftContentState(
15911593
context,
15921594
...(importedShareIds ? { importedShareIds } : {}),
15931595
},
1594-
attachments.slice(existing.attachments.length),
1596+
content.sourceShareId ? attachments.slice(existing.attachments.length) : [],
15951597
),
15961598
};
15971599
}

0 commit comments

Comments
 (0)