Open History to see the last commit
1export interface SentImageHandoff {
2 readonly uri: string;
3 readonly aspectRatio: number;
4}
5
6// A sent image's local pixels and shape, so the pending bubble and then the delivered copy open at
7// their final size over pixels already on screen instead of a placeholder that later resizes.
8// The server re-ids attachments into the thread, so delivered images match by message and position.
9const MAX_ENTRIES = 64;
10const images = new Map<string, SentImageHandoff>();
11
12function remember(key: string, image: SentImageHandoff) {
13 if (!Number.isFinite(image.aspectRatio) || image.aspectRatio <= 0) return;
14 images.delete(key);
15 images.set(key, image);
16 if (images.size > MAX_ENTRIES) images.delete(images.keys().next().value!);
17}
18
19export function rememberDraftImage(attachmentId: string, image: SentImageHandoff): void {
20 remember(`draft:${attachmentId}`, image);
21}
22
23export function rememberSentImage(messageId: string, index: number, image: SentImageHandoff): void {
24 remember(`message:${messageId}:${index}`, image);
25}
26
27export function sentImageHandoff(
28 messageId: string,
29 index: number,
30 draftAttachmentId?: string,
31): SentImageHandoff | undefined {
32 return (
33 images.get(`message:${messageId}:${index}`) ??
34 (draftAttachmentId === undefined ? undefined : images.get(`draft:${draftAttachmentId}`))
35 );
36}