Skip to content

Commit 03f3881

Browse files
maria-rckstris203
andcommitted
fix(mobile): preserve recovery after queued attachment removal
Co-authored-by: Tristan Knight <[email protected]>
1 parent 08c617c commit 03f3881

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎apps/mobile/src/state/queued-run-edit.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
endQueuedRunEdit,
1414
getQueuedRunEdit,
1515
recoverQueuedRunEdit,
16+
removeQueuedRunEditAttachment,
1617
queuedEditDraftKey,
1718
resolveQueuedEditPayload,
1819
type QueuedRunEdit,
@@ -136,6 +137,18 @@ describe("recoverQueuedRunEdit", () => {
136137
expect(recovery).toBe("clean");
137138
});
138139

140+
it("recovers text after an existing attachment was removed", async () => {
141+
beginQueuedRunEdit(threadKey, edit([image("removed")]));
142+
removeQueuedRunEditAttachment(threadKey, "removed");
143+
144+
const recovery = recoverQueuedRunEdit(threadKey, runId);
145+
await flushComposerDrafts();
146+
147+
expect(getComposerDraftSnapshot(threadKey).text).toBe("original");
148+
expect(getQueuedRunEdit(threadKey)).toBeNull();
149+
expect(recovery).toBe("kept");
150+
});
151+
139152
it("recovers a changed edit into an empty thread draft", async () => {
140153
beginQueuedRunEdit(threadKey, edit([]));
141154
setComposerDraftText(editKey, "revised");

‎apps/mobile/src/state/queued-run-edit.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface QueuedRunEdit {
2323
readonly runId: RunId;
2424
readonly messageId: MessageId;
2525
readonly originalText: string;
26+
readonly attachmentsChanged?: boolean;
2627
readonly existingAttachments: ReadonlyArray<ChatAttachment>;
2728
readonly context?: OrchestrationMessageContext;
2829
}
@@ -73,6 +74,9 @@ export function removeQueuedRunEditAttachment(threadKey: string, attachmentId: s
7374
if (edit === null) return;
7475
setQueuedRunEdit(threadKey, {
7576
...edit,
77+
attachmentsChanged:
78+
edit.attachmentsChanged ||
79+
edit.existingAttachments.some((attachment) => attachment.id === attachmentId),
7680
existingAttachments: edit.existingAttachments.filter(
7781
(attachment) => attachment.id !== attachmentId,
7882
),
@@ -97,7 +101,11 @@ export function recoverQueuedRunEdit(
97101
if (edit === null || edit.runId !== runId) return null;
98102
const editDraftKey = queuedEditDraftKey(threadKey, runId);
99103
const editDraft = getComposerDraftSnapshot(editDraftKey);
100-
if (editDraft.text === edit.originalText && editDraft.attachments.length === 0) {
104+
if (
105+
!edit.attachmentsChanged &&
106+
editDraft.text === edit.originalText &&
107+
editDraft.attachments.length === 0
108+
) {
101109
endQueuedRunEdit(threadKey);
102110
return "clean";
103111
}

0 commit comments

Comments
 (0)