Complete attachment-encryption patch

https://github.com/matrix-org/matrix-react-sdk/pull/533 originally landed in
the wrong branch, and was reverted by
https://github.com/matrix-org/matrix-react-sdk/pull/546.
https://github.com/matrix-org/matrix-react-sdk/pull/548 attempted to land it on
the develop branch, but omitted a small amount of the patch.

This lands the final part, which got missed out.
This commit is contained in:
Richard van der Hoff 2016-11-12 12:20:36 +00:00
parent 062cb7a52e
commit 34df6ea242

View file

@ -23,6 +23,8 @@ var MatrixClientPeg = require('./MatrixClientPeg');
var sdk = require('./index');
var Modal = require('./Modal');
var encrypt = require("browser-encrypt-attachment");
function infoForImageFile(imageFile) {
var deferred = q.defer();
@ -155,10 +157,26 @@ class ContentMessages {
this.inprogress.push(upload);
dis.dispatch({action: 'upload_started'});
var encryptInfo = null;
var error;
var self = this;
return def.promise.then(function() {
if (matrixClient.isRoomEncrypted(roomId)) {
// If the room is encrypted then encrypt the file before uploading it.
// First read the file into memory.
upload.promise = readFileAsArrayBuffer(file).then(function(data) {
// Then encrypt the file.
return encrypt.encryptAttachment(data);
}).then(function(encryptResult) {
// Record the information needed to decrypt the attachment.
encryptInfo = encryptResult.info;
// Pass the encrypted data as a Blob to the uploader.
var blob = new Blob([encryptResult.data]);
return matrixClient.uploadContent(blob);
});
} else {
upload.promise = matrixClient.uploadContent(file);
}
return upload.promise;
}).progress(function(ev) {
if (ev) {