@@ -31,6 +31,14 @@ type QueuedMessageEditHost = ChatQueueScopedSessionHost & {
3131 chatQueuedEdit ?: QueuedMessageEdit | null ;
3232} ;
3333
34+ function releaseUnretainedAttachments (
35+ owned : readonly ChatAttachment [ ] ,
36+ retained : readonly ChatAttachment [ ] ,
37+ ) : void {
38+ const retainedIds = new Set ( retained . map ( ( attachment ) => attachment . id ) ) ;
39+ releaseChatAttachmentPayloads ( owned . filter ( ( attachment ) => ! retainedIds . has ( attachment . id ) ) ) ;
40+ }
41+
3442/** Closed outcomes so the page owns the operator-visible wording. */
3543type QueuedMessageEditResult = "started" | "unavailable" | "composer-busy" ;
3644
@@ -94,9 +102,13 @@ export function beginQueuedMessageEdit(
94102
95103/** Cancel touches storage not at all: the row never left the queue. */
96104export function cancelQueuedMessageEdit ( host : QueuedMessageEditHost ) : boolean {
97- if ( ! activeQueuedMessageEdit ( host ) ) {
105+ const edit = activeQueuedMessageEdit ( host ) ;
106+ if ( ! edit ) {
98107 return false ;
99108 }
109+ // The durable row still owns its original payloads, but anything attached in
110+ // the composer during the edit has no owner after cancellation.
111+ releaseUnretainedAttachments ( host . chatAttachments , edit . attachments ) ;
100112 host . chatQueuedEdit = null ;
101113 host . chatMessage = "" ;
102114 host . chatAttachments = [ ] ;
@@ -128,8 +140,5 @@ export function retireEditedQueuedMessageSource(
128140 // ones the replacement still carries must survive, so release only the rest.
129141 // The payloads come from the token: a successful write already retired the row
130142 // and told every pane, so re-reading it here would find nothing to release.
131- const retained = new Set ( nextAttachments . map ( ( attachment ) => attachment . id ) ) ;
132- releaseChatAttachmentPayloads (
133- edit . attachments . filter ( ( attachment ) => ! retained . has ( attachment . id ) ) ,
134- ) ;
143+ releaseUnretainedAttachments ( edit . attachments , nextAttachments ) ;
135144}
0 commit comments