Make the promises be q promises

pull/21833/head
Mark Haines 2016-11-08 16:26:25 +00:00
parent 9edfea3b32
commit 72d24f58d0
2 changed files with 11 additions and 12 deletions

View File

@ -16,12 +16,13 @@ limitations under the License.
'use strict'; 'use strict';
import React from require('react'); import React from 'react';
import MFileBody from './MFileBody'; import MFileBody from './MFileBody';
import MatrixClientPeg from '../../../MatrixClientPeg'; import MatrixClientPeg from '../../../MatrixClientPeg';
import Model from '../../../Modal'; import Model from '../../../Modal';
import sdk from '../../../index'; import sdk from '../../../index';
import {decryptFile} from '../../../utils/DecryptFile'; import { decryptFile } from '../../../utils/DecryptFile';
import q from 'q';
module.exports = React.createClass({ module.exports = React.createClass({
displayName: 'MVideoBody', displayName: 'MVideoBody',
@ -78,26 +79,24 @@ module.exports = React.createClass({
componentDidMount: function() { componentDidMount: function() {
const content = this.props.mxEvent.getContent(); const content = this.props.mxEvent.getContent();
if (content.file !== undefined && this.state.decryptedUrl === null) { if (content.file !== undefined && this.state.decryptedUrl === null) {
var thumbnailPromise = Promise.resolve(null); var thumbnailPromise = q(null);
if (content.info.thumbnail_file) { if (content.info.thumbnail_file) {
thumbnailPromise = decryptFile( thumbnailPromise = decryptFile(
content.info.thumbnail_file content.info.thumbnail_file
); );
} }
thumbnailPromise.then(function (thumbnailUrl) { thumbnailPromise.then((thumbnailUrl) => {
decryptFile(content.file).then(function(contentUrl) { decryptFile(content.file).then((contentUrl) => {
return { this.setState({
decryptedUrl: contentUrl, decryptedUrl: contentUrl,
decryptedThumbnailUrl: thumbnailUrl, decryptedThumbnailUrl: thumbnailUrl,
}; });
}); });
}).done((state) => { }).catch((err) => {
this.setState(result);
}, (err) => {
console.warn("Unable to decrypt attachment: ", err) console.warn("Unable to decrypt attachment: ", err)
// Set a placeholder image when we can't decrypt the image. // Set a placeholder image when we can't decrypt the image.
this.refs.image.src = "img/warning.svg"; this.refs.image.src = "img/warning.svg";
}); }).done();
} }
}, },

View File

@ -53,7 +53,7 @@ function readBlobAsDataUri(file) {
export function decryptFile(file) { export function decryptFile(file) {
const url = MatrixClientPeg.get().mxcUrlToHttp(file.url); const url = MatrixClientPeg.get().mxcUrlToHttp(file.url);
// Download the encrypted file as an array buffer. // Download the encrypted file as an array buffer.
return fetch(url).then(function(response) { return q(fetch(url)).then(function(response) {
return response.arrayBuffer(); return response.arrayBuffer();
}).then(function(responseData) { }).then(function(responseData) {
// Decrypt the array buffer using the information taken from // Decrypt the array buffer using the information taken from