Open History to see the last commit
1import type { FileBackedComposerAttachment } from "./composerImages";
2import { retainComposerAttachmentFile } from "./composerAttachmentFiles";
3
4/**
5 * The durable owners of an attachment file (composer drafts, queued outbox
6 * messages) live in state, so this module cannot reach the ownership-cleanup
7 * sweep directly. Composer draft state registers the owner-side cleanup hook
8 * at module load; until then a release has nothing to retry, because no draft
9 * store has loaded yet and there is nothing to clean.
10 */
11type UnusedAttachmentHandler = (attachment: FileBackedComposerAttachment) => void;
12
13let onAttachmentUnused: UnusedAttachmentHandler | null = null;
14
15export function registerComposerAttachmentUnusedHandler(handler: UnusedAttachmentHandler): void {
16 onAttachmentUnused = handler;
17}
18
19export function retainComposerAttachmentFileForPreview(
20 attachment: FileBackedComposerAttachment,
21): () => void {
22 return retainComposerAttachmentFile(attachment.fileUri, () => {
23 onAttachmentUnused?.(attachment);
24 });
25}