From e534dd64f20e9c5d48bb0380cd47ebfbfe694acd Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 20 Jul 2021 12:31:23 -0700 Subject: [PATCH] Don't transcode incoming attachments --- js/modules/types/message.js | 6 +++++- ts/types/Attachment.ts | 14 ++++++++++++-- ts/views/conversation_view.ts | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/js/modules/types/message.js b/js/modules/types/message.js index a07c1a2a7..44e663915 100644 --- a/js/modules/types/message.js +++ b/js/modules/types/message.js @@ -458,7 +458,11 @@ exports.processNewAttachment = async ( throw new TypeError('context.logger is required'); } - const rotatedAttachment = await Attachment.autoOrientJPEG(attachment); + const rotatedAttachment = await Attachment.autoOrientJPEG( + attachment, + undefined, + { isIncoming: true } + ); const onDiskAttachment = await Attachment.migrateDataToFileSystem( rotatedAttachment, { writeNewAttachmentData } diff --git a/ts/types/Attachment.ts b/ts/types/Attachment.ts index 809411ec0..35c91df87 100644 --- a/ts/types/Attachment.ts +++ b/ts/types/Attachment.ts @@ -180,8 +180,18 @@ export function isValid( export async function autoOrientJPEG( attachment: AttachmentType, _: unknown, - message?: { sendHQImages?: boolean } + { + sendHQImages = false, + isIncoming = false, + }: { + sendHQImages?: boolean; + isIncoming?: boolean; + } = {} ): Promise { + if (isIncoming && !MIME.isJPEG(attachment.contentType)) { + return attachment; + } + if (!canBeTranscoded(attachment)) { return attachment; } @@ -197,7 +207,7 @@ export async function autoOrientJPEG( ); const xcodedDataBlob = await scaleImageToLevel( dataBlob, - message ? message.sendHQImages : false + sendHQImages || isIncoming ); const xcodedDataArrayBuffer = await blobToArrayBuffer(xcodedDataBlob); diff --git a/ts/views/conversation_view.ts b/ts/views/conversation_view.ts index 9240aa1e3..7a2b5189b 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -3702,7 +3702,7 @@ Whisper.ConversationView = Whisper.View.extend({ } }, - async sendStickerMessage(options: any = {}) { + async sendStickerMessage(options: { packId: string; stickerId: number }) { const { model }: { model: ConversationModel } = this; try {