From ff3b36d37b99c85e7c1aa8a686fffa12f0fc7713 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 20 Jul 2021 13:09:13 -0700 Subject: [PATCH] Don't transcode incoming attachments --- js/modules/types/attachment.js | 13 +++++++++++-- js/modules/types/message.js | 6 +++++- ts/views/conversation_view.ts | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/js/modules/types/attachment.js b/js/modules/types/attachment.js index 7881b3909a..4c36750aef 100644 --- a/js/modules/types/attachment.js +++ b/js/modules/types/attachment.js @@ -5,6 +5,7 @@ const is = require('@sindresorhus/is'); const { arrayBufferToBlob, blobToArrayBuffer } = require('blob-util'); const AttachmentTS = require('../../../ts/types/Attachment'); +const MIME = require('../../../ts/types/MIME'); const GoogleChrome = require('../../../ts/util/GoogleChrome'); const { toLogFormat } = require('./errors'); const { scaleImageToLevel } = require('../../../ts/util/scaleImageToLevel'); @@ -49,7 +50,15 @@ exports.isValid = rawAttachment => { // Upgrade steps // NOTE: This step strips all EXIF metadata from JPEG images as // part of re-encoding the image: -exports.autoOrientJPEG = async (attachment, _, message) => { +exports.autoOrientJPEG = async ( + attachment, + _, + { sendHQImages = false, isIncoming = false } = {} +) => { + if (isIncoming && !MIME.isJPEG(attachment.contentType)) { + return attachment; + } + if (!AttachmentTS.canBeTranscoded(attachment)) { return attachment; } @@ -65,7 +74,7 @@ exports.autoOrientJPEG = async (attachment, _, message) => { ); const xcodedDataBlob = await scaleImageToLevel( dataBlob, - message ? message.sendHQImages : false + sendHQImages || isIncoming ); const xcodedDataArrayBuffer = await blobToArrayBuffer(xcodedDataBlob); diff --git a/js/modules/types/message.js b/js/modules/types/message.js index 958cb9c126..927c764975 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/views/conversation_view.ts b/ts/views/conversation_view.ts index 390e58de99..905f7fab2a 100644 --- a/ts/views/conversation_view.ts +++ b/ts/views/conversation_view.ts @@ -3672,7 +3672,7 @@ Whisper.ConversationView = Whisper.View.extend({ } }, - async sendStickerMessage(options: any = {}) { + async sendStickerMessage(options: { packId: string; stickerId: number }) { const { model }: { model: ConversationModel } = this; try {