Move to central MIME functions, remove some console.log

And generally address PR feedback.
This commit is contained in:
Scott Nonnenberg 2018-04-12 19:02:20 -07:00
parent f255cbcbe3
commit fce9bb7342
No known key found for this signature in database
GPG key ID: 5F82280C35134661
6 changed files with 21 additions and 17 deletions

View file

@ -1137,13 +1137,11 @@
// Maybe in the future we could try to pull thumbnails video ourselves,
// but for now we will rely on incoming thumbnails only.
console.log({ first, contentType: first ? first.contentType : null });
if (!first || !MIME.isImage(first.contentType)) {
return;
}
const quotedAttachments = quotedMessage.get('attachments') || [];
console.log({ quotedMessage, quotedAttachments });
if (quotedAttachments.length === 0) {
return;
}
@ -1155,7 +1153,6 @@
// Note: it would be nice to take the full-size image and downsample it into
// a true thumbnail here.
quotedMessage.updateImageUrl();
console.log({ quotedMessage });
},
async loadQuoteThumbnail(message) {
const { quote } = message.attributes;

View file

@ -12,6 +12,7 @@
'use strict';
const ESCAPE_KEY_CODE = 27;
const { Signal } = window;
const FileView = Whisper.View.extend({
tagName: 'div',
@ -133,15 +134,16 @@
return false;
},
isAudio() {
return this.model.contentType.startsWith('audio/');
const { contentType } = this.model;
return Signal.Types.MIME.isAudio(contentType);
},
isVideo() {
const type = this.model.contentType;
return type.startsWith('video/') && type !== 'image/wmv';
const { contentType } = this.model;
return Signal.Types.MIME.isVideo(contentType);
},
isImage() {
const type = this.model.contentType;
return type.startsWith('image/') && type !== 'image/tiff';
const { contentType } = this.model;
return Signal.Types.MIME.isImage(contentType);
},
mediaType() {
if (this.isVoiceMessage()) {

View file

@ -10,7 +10,7 @@
(function () {
'use strict';
const { HTML } = window.Signal;
const { Signal } = window;
const { loadAttachmentData } = window.Signal.Migrations;
window.Whisper = window.Whisper || {};
@ -401,7 +401,7 @@
return Object.assign({}, attachment, {
// eslint-disable-next-line no-bitwise
isVoiceMessage: attachment.flags & VOICE_FLAG,
isVoiceMessage: Boolean(attachment.flags & VOICE_FLAG),
thumbnail,
});
}
@ -456,7 +456,7 @@
}
const first = attachments[0];
if (first.contentType.startsWith('image/') && first.contentType !== 'image/tiff') {
if (Signal.Types.MIME.isImage(first.contentType)) {
return true;
}
@ -483,7 +483,7 @@
if (body.length > 0) {
const escapedBody = body.html();
body.html(HTML.render(escapedBody));
body.html(Signal.HTML.render(escapedBody));
}
this.renderSent();

View file

@ -359,9 +359,9 @@ describe('Message', () => {
});
it('calls provided async function for each quoted attachment', async () => {
const upgradeAttachment = sinon.stub().returns(Promise.resolve({
const upgradeAttachment = sinon.stub().resolves({
path: '/new/path/on/disk',
}));
});
const upgradeVersion = Message._mapQuotedAttachments(upgradeAttachment);
const message = {

View file

@ -24,9 +24,6 @@ window.libphonenumber = {
};
window.Signal = {};
window.Signal.HTML = {
render: thing => thing,
};
window.Signal.Backup = {};
window.Signal.Crypto = {};
window.Signal.Logs = {};
@ -54,6 +51,9 @@ window.EmojiConvertor.prototype.img_sets = {
window.i18n = () => '';
// Ideally we don't need to add things here. We want to add them in StyleGuideUtil, which
// means that references to these things can't be early-bound, not capturing the direct
// reference to the function on file load.
window.Signal.Migrations.V17 = {};
window.Signal.OS = {};
window.Signal.Types = {};

View file

@ -18,7 +18,10 @@ export { BackboneWrapper } from '../components/utility/BackboneWrapper';
// Here we can make things inside Webpack available to Backbone views like preload.js.
import { Quote } from '../components/conversation/Quote';
import * as HTML from '../html';
// @ts-ignore
import MIME from '../../js/modules/types/mime';
// TypeScript wants two things when you import:
// 1) a normal typescript file
@ -98,6 +101,8 @@ parent.moment.locale(locale);
parent.React = React;
parent.ReactDOM = ReactDOM;
parent.Signal.HTML = HTML;
parent.Signal.Types.MIME = MIME;
parent.Signal.Components = {
Quote,
};