From 93ddb5539eca91431ac8135e554c1f984e6ecd98 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 8 Nov 2016 12:57:24 +0000 Subject: [PATCH] Make imports more consistent, fix m.video --- src/components/views/messages/MFileBody.js | 12 ++++---- src/components/views/messages/MImageBody.js | 31 ++++++++++----------- src/components/views/messages/MVideoBody.js | 16 +++++------ 3 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/components/views/messages/MFileBody.js b/src/components/views/messages/MFileBody.js index a1512738fd..e8c97e5f44 100644 --- a/src/components/views/messages/MFileBody.js +++ b/src/components/views/messages/MFileBody.js @@ -16,11 +16,11 @@ limitations under the License. 'use strict'; -var React = require('react'); -var filesize = require('filesize'); -var MatrixClientPeg = require('../../../MatrixClientPeg'); -var sdk = require('../../../index'); -var DecryptFile = require('../../../utils/DecryptFile'); +import React from 'react'; +import filesize from 'filesize'; +import MatrixClientPeg from '../../../MatrixClientPeg'; +import sdk from '../../../index'; +import {decryptFile} from '../../../utils/DecryptFile'; module.exports = React.createClass({ @@ -66,7 +66,7 @@ module.exports = React.createClass({ componentDidMount: function() { const content = this.props.mxEvent.getContent(); if (content.file !== undefined && this.state.decryptedUrl === null) { - DecryptFile.decryptFile(content.file).done((url) => { + decryptFile(content.file).done((url) => { this.setState({ decryptedUrl: url, }); diff --git a/src/components/views/messages/MImageBody.js b/src/components/views/messages/MImageBody.js index 6784cede7a..4a3cfce591 100644 --- a/src/components/views/messages/MImageBody.js +++ b/src/components/views/messages/MImageBody.js @@ -23,7 +23,7 @@ import ImageUtils from '../../../ImageUtils'; import Modal from '../../../Modal'; import sdk from '../../../index'; import dis from '../../../dispatcher'; -import DecryptFile from '../../../utils/DecryptFile'; +import {decryptFile} from '../../../utils/DecryptFile'; module.exports = React.createClass({ @@ -44,10 +44,10 @@ module.exports = React.createClass({ onClick: function onClick(ev) { if (ev.button == 0 && !ev.metaKey) { ev.preventDefault(); - var content = this.props.mxEvent.getContent(); - var httpUrl = this._getContentUrl(); - var ImageView = sdk.getComponent("elements.ImageView"); - var params = { + const content = this.props.mxEvent.getContent(); + const httpUrl = this._getContentUrl(); + const ImageView = sdk.getComponent("elements.ImageView"); + const params = { src: httpUrl, mxEvent: this.props.mxEvent }; @@ -63,7 +63,7 @@ module.exports = React.createClass({ }, _isGif: function() { - var content = this.props.mxEvent.getContent(); + const content = this.props.mxEvent.getContent(); return (content && content.info && content.info.mimetype === "image/gif"); }, @@ -107,7 +107,7 @@ module.exports = React.createClass({ this.fixupHeight(); const content = this.props.mxEvent.getContent(); if (content.file !== undefined && this.state.decryptedUrl === null) { - DecryptFile.decryptFile(content.file).done((url) => { + decryptFile(content.file).done((url) => { this.setState({ decryptedUrl: url, }); @@ -135,14 +135,13 @@ module.exports = React.createClass({ return; } - var content = this.props.mxEvent.getContent(); - - var thumbHeight = null; - var timelineWidth = this.refs.body.offsetWidth; - var maxHeight = 600; // let images take up as much width as they can so long as the height doesn't exceed 600px. + const content = this.props.mxEvent.getContent(); + const timelineWidth = this.refs.body.offsetWidth; + const maxHeight = 600; // let images take up as much width as they can so long as the height doesn't exceed 600px. // the alternative here would be 600*timelineWidth/800; to scale them down to fit inside a 4:3 bounding box //console.log("trying to fit image into timelineWidth of " + this.refs.body.offsetWidth + " or " + this.refs.body.clientWidth); + var thumbHeight = null; if (content.info) { thumbHeight = ImageUtils.thumbHeight(content.info.w, content.info.h, timelineWidth, maxHeight); } @@ -151,8 +150,8 @@ module.exports = React.createClass({ }, render: function() { - var TintableSvg = sdk.getComponent("elements.TintableSvg"); - var content = this.props.mxEvent.getContent(); + const TintableSvg = sdk.getComponent("elements.TintableSvg"); + const content = this.props.mxEvent.getContent(); if (content.file !== undefined && this.state.decryptedUrl === null) { @@ -167,8 +166,8 @@ module.exports = React.createClass({ ); } - var contentUrl = this._getContentUrl(); - var thumbUrl = this._getThumbUrl(); + const contentUrl = this._getContentUrl(); + const thumbUrl = this._getThumbUrl(); if (thumbUrl) { return ( diff --git a/src/components/views/messages/MVideoBody.js b/src/components/views/messages/MVideoBody.js index 4e60e17e40..c5fc0f9802 100644 --- a/src/components/views/messages/MVideoBody.js +++ b/src/components/views/messages/MVideoBody.js @@ -21,7 +21,7 @@ import MFileBody from './MFileBody'; import MatrixClientPeg from '../../../MatrixClientPeg'; import Model from '../../../Modal'; import sdk from '../../../index'; -import DecryptFile from '../../../utils/DecryptFile'; +import {decryptFile} from '../../../utils/DecryptFile'; module.exports = React.createClass({ displayName: 'MVideoBody', @@ -80,19 +80,19 @@ module.exports = React.createClass({ if (content.file !== undefined && this.state.decryptedUrl === null) { var thumbnailPromise = Promise.resolve(null); if (content.info.thumbnail_file) { - thumbnailPromise = DecryptFile.decryptFile( + thumbnailPromise = decryptFile( content.info.thumbnail_file ); } - thumbnailPromise.done((thumbnailUrl) => { - DecryptFile.decryptFile( - content.file - ).then(function(contentUrl) { - this.setState({ + thumbnailPromise.then(function (thumbnailUrl) { + decryptFile(content.file).then(function(contentUrl) { + return { decryptedUrl: contentUrl, decryptedThumbnailUrl: thumbnailUrl, - }); + }; }); + }).done((state) => { + this.setState(result); }, (err) => { console.warn("Unable to decrypt attachment: ", err) // Set a placeholder image when we can't decrypt the image.