Make imports more consistent, fix m.video

This commit is contained in:
Mark Haines 2016-11-08 12:57:24 +00:00
parent 911f9e4e63
commit 93ddb5539e
3 changed files with 29 additions and 30 deletions

View file

@ -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,
});

View file

@ -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 (

View file

@ -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.