From cea2c2460a507f798a3d0bb0a14bbb7d0217f73c Mon Sep 17 00:00:00 2001 From: audric Date: Thu, 13 Jan 2022 16:00:23 +1100 Subject: [PATCH] make sure screenshot of video attachment is saved locally --- .../conversation/composition/CompositionBox.tsx | 1 - ts/models/conversation.ts | 1 - ts/types/Attachment.ts | 13 ++++++------- ts/types/MessageAttachment.ts | 2 -- ts/types/attachments/migrations.ts | 1 + ts/util/attachmentsUtil.ts | 4 ++-- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ts/components/conversation/composition/CompositionBox.tsx b/ts/components/conversation/composition/CompositionBox.tsx index 56bce352e..fa347f4dd 100644 --- a/ts/components/conversation/composition/CompositionBox.tsx +++ b/ts/components/conversation/composition/CompositionBox.tsx @@ -874,7 +874,6 @@ class CompositionBoxInner extends React.Component { } else { // scale them down const files = await Promise.all(stagedAttachments.map(AttachmentUtil.getFileAndStoreLocally)); - attachments = _.compact(files); } diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index e600520a3..ecacaad35 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -1636,7 +1636,6 @@ const trotthledAllConversationsDispatch = _.throttle(() => { if (updatesToDispatch.size === 0) { return; } - console.warn('updatesToDispatch.size ', updatesToDispatch.size); window.inboxStore?.dispatch(conversationsChanged([...updatesToDispatch.values()])); updatesToDispatch.clear(); diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index 2f73a4ed7..671ef5819 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -108,13 +108,13 @@ export function canDisplayImage(attachments?: Array) { const { height, width } = attachments && attachments[0] ? attachments[0] : { height: 0, width: 0 }; - return ( + return Boolean( height && - height > 0 && - height <= ATTACHMENT_DEFAULT_MAX_SIDE && - width && - width > 0 && - width <= ATTACHMENT_DEFAULT_MAX_SIDE + height > 0 && + height <= ATTACHMENT_DEFAULT_MAX_SIDE && + width && + width > 0 && + width <= ATTACHMENT_DEFAULT_MAX_SIDE ); } @@ -164,7 +164,6 @@ export function isVideoAttachment(attachment?: AttachmentType): boolean { export function hasVideoScreenshot(attachments?: Array): boolean { const firstAttachment = attachments ? attachments[0] : null; - return Boolean(firstAttachment?.screenshot?.url); } diff --git a/ts/types/MessageAttachment.ts b/ts/types/MessageAttachment.ts index f74538bda..59239ec2a 100644 --- a/ts/types/MessageAttachment.ts +++ b/ts/types/MessageAttachment.ts @@ -134,8 +134,6 @@ export const loadQuoteData = async (quote: any) => { if (!quote) { return null; } - console.warn('loadQuoteData', quote); - if (!quote.attachments?.length || isEmpty(quote.attachments[0])) { return quote; } diff --git a/ts/types/attachments/migrations.ts b/ts/types/attachments/migrations.ts index 8e8cb6e5b..a34f45e7a 100644 --- a/ts/types/attachments/migrations.ts +++ b/ts/types/attachments/migrations.ts @@ -271,6 +271,7 @@ export const captureDimensionsAndScreenshot = async ( const { width, height } = await getImageDimensions({ objectUrl: screenshotObjectUrl, }); + const screenshotPath = await writeNewAttachmentData(screenshotBuffer); const thumbnailBuffer = await makeImageThumbnailBuffer({ diff --git a/ts/util/attachmentsUtil.ts b/ts/util/attachmentsUtil.ts index 1b2ee57e1..247dd297a 100644 --- a/ts/util/attachmentsUtil.ts +++ b/ts/util/attachmentsUtil.ts @@ -276,8 +276,8 @@ export async function getFileAndStoreLocally( contentType: attachment.contentType, fileName: attachment.fileName, path: attachmentSavedLocally.path, - width: scaled.width, - height: scaled.height, + width: attachmentSavedLocally.width, + height: attachmentSavedLocally.height, screenshot: attachmentSavedLocally.screenshot, thumbnail: attachmentSavedLocally.thumbnail, size: attachmentSavedLocally.size,