From b65370c8d7e36b51f5a51b1392230397a7a2821c Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Tue, 24 Apr 2018 17:16:26 -0400 Subject: [PATCH] Prefer `GoogleChrome.is*` over `MIME.is*` --- js/models/conversations.js | 13 ++++++++----- js/views/attachment_view.js | 5 +++-- js/views/message_view.js | 2 +- ts/components/conversation/Quote.tsx | 9 +++++---- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 03182f3c8ce..aa54058718e 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -17,7 +17,7 @@ window.Whisper = window.Whisper || {}; - const { Message, MIME } = window.Signal.Types; + const { Message } = window.Signal.Types; const { upgradeMessageSchema, loadAttachmentData } = window.Signal.Migrations; // TODO: Factor out private and group subclasses of Conversation @@ -651,7 +651,8 @@ text: quotedMessage.get('body'), attachments: await Promise.all((attachments || []).map(async (attachment) => { const { contentType } = attachment; - const willMakeThumbnail = MIME.isImage(contentType); + const willMakeThumbnail = + Signal.Util.GoogleChrome.isImageTypeSupported(contentType); return { contentType, @@ -1111,7 +1112,9 @@ const first = attachments[0]; const { thumbnail, contentType } = first; - return thumbnail || MIME.isVideo(contentType) || MIME.isImage(contentType); + return thumbnail || + Signal.Util.GoogleChrome.isImageTypeSupported(contentType) || + Signal.Util.GoogleChrome.isVideoTypeSupported(contentType); }, forceRender(message) { message.trigger('change', message); @@ -1151,7 +1154,7 @@ // Maybe in the future we could try to pull the thumbnail from a video ourselves, // but for now we will rely on incoming thumbnails only. - if (!MIME.isImage(first.contentType)) { + if (!Signal.Util.GoogleChrome.isImageTypeSupported(first.contentType)) { return false; } @@ -1191,7 +1194,7 @@ // Maybe in the future we could try to pull thumbnails video ourselves, // but for now we will rely on incoming thumbnails only. - if (!first || !MIME.isImage(first.contentType)) { + if (!first || !Signal.Util.GoogleChrome.isImageTypeSupported(first.contentType)) { return; } diff --git a/js/views/attachment_view.js b/js/views/attachment_view.js index 0ac5a5e7f26..209140159be 100644 --- a/js/views/attachment_view.js +++ b/js/views/attachment_view.js @@ -142,15 +142,16 @@ }, isAudio() { const { contentType } = this.model; + // TODO: Implement and use `Signal.Util.GoogleChrome.isAudioTypeSupported`: return Signal.Types.MIME.isAudio(contentType); }, isVideo() { const { contentType } = this.model; - return Signal.Types.MIME.isVideo(contentType); + return Signal.Util.GoogleChrome.isVideoTypeSupported(contentType); }, isImage() { const { contentType } = this.model; - return Signal.Types.MIME.isImage(contentType); + return Signal.Util.GoogleChrome.isImageTypeSupported(contentType); }, mediaType() { if (this.isVoiceMessage()) { diff --git a/js/views/message_view.js b/js/views/message_view.js index 458883cb825..e20a2f92df8 100644 --- a/js/views/message_view.js +++ b/js/views/message_view.js @@ -429,7 +429,7 @@ } const first = attachments[0]; - if (Signal.Types.MIME.isImage(first.contentType)) { + if (Signal.Util.GoogleChrome.isImageTypeSupported(first.contentType)) { return true; } diff --git a/ts/components/conversation/Quote.tsx b/ts/components/conversation/Quote.tsx index 6cb2bfa133b..d71f6f36d08 100644 --- a/ts/components/conversation/Quote.tsx +++ b/ts/components/conversation/Quote.tsx @@ -2,6 +2,7 @@ import React from 'react'; import classnames from 'classnames'; import * as MIME from '../../../ts/types/MIME'; +import * as GoogleChrome from '../../../ts/util/GoogleChrome'; interface Props { @@ -91,12 +92,12 @@ export class Quote extends React.Component { const { contentType, thumbnail } = first; const objectUrl = getObjectUrl(thumbnail); - if (MIME.isVideo(contentType)) { + if (GoogleChrome.isVideoTypeSupported(contentType)) { return objectUrl ? this.renderImage(objectUrl, 'play') : this.renderIcon('movie'); } - if (MIME.isImage(contentType)) { + if (GoogleChrome.isImageTypeSupported(contentType)) { return objectUrl ? this.renderImage(objectUrl) : this.renderIcon('image'); @@ -122,10 +123,10 @@ export class Quote extends React.Component { const first = attachments[0]; const { contentType, fileName, isVoiceMessage } = first; - if (MIME.isVideo(contentType)) { + if (GoogleChrome.isVideoTypeSupported(contentType)) { return
{i18n('video')}
; } - if (MIME.isImage(contentType)) { + if (GoogleChrome.isImageTypeSupported(contentType)) { return
{i18n('photo')}
; } if (MIME.isAudio(contentType) && isVoiceMessage) {