diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index b45aa7791..02e151565 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -113,6 +113,8 @@ export type AttachmentDraftType = caption?: string; fileName?: string; path: string; + width?: number; + height?: number; } & BaseAttachmentDraftType) | { contentType: MIME.MIMEType; diff --git a/ts/util/resolveDraftAttachmentOnDisk.ts b/ts/util/resolveDraftAttachmentOnDisk.ts index 27765aaa6..c83c2414d 100644 --- a/ts/util/resolveDraftAttachmentOnDisk.ts +++ b/ts/util/resolveDraftAttachmentOnDisk.ts @@ -34,6 +34,8 @@ export function resolveDraftAttachmentOnDisk( 'fileName', 'path', 'size', + 'width', + 'height', ]), pending: false, url, diff --git a/ts/util/writeDraftAttachment.ts b/ts/util/writeDraftAttachment.ts index b233ebd92..a19a6a3d2 100644 --- a/ts/util/writeDraftAttachment.ts +++ b/ts/util/writeDraftAttachment.ts @@ -6,6 +6,10 @@ import type { InMemoryAttachmentDraftType, AttachmentDraftType, } from '../types/Attachment'; +import { isImageAttachment } from '../types/Attachment'; +import { getImageDimensions } from '../types/VisualAttachment'; +import * as Errors from '../types/errors'; +import * as logger from '../logging/log'; export async function writeDraftAttachment( attachment: InMemoryAttachmentDraftType @@ -24,10 +28,28 @@ export async function writeDraftAttachment( ) : undefined; + let dimensions: { width?: number; height?: number } = {}; + if (isImageAttachment(attachment)) { + const url = window.Signal.Migrations.getAbsoluteDraftPath(path); + + try { + dimensions = await getImageDimensions({ + objectUrl: url, + logger, + }); + } catch (error) { + logger.error( + 'writeDraftAttachment: failed to capture image dimensions', + Errors.toLogFormat(error) + ); + } + } + return { ...omit(attachment, ['data', 'screenshotData']), path, screenshotPath, pending: false, + ...dimensions, }; }