From ee2f43aba4c87dba7cc796a60b267279e113a818 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 19 May 2014 03:06:28 -0400 Subject: [PATCH] Fix, display (image) attachments --- js/crypto.js | 5 ++--- js/helpers.js | 4 +++- js/models/messages.js | 6 ++++++ js/views/messages.js | 6 ++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/js/crypto.js b/js/crypto.js index f253036b..0b34353d 100644 --- a/js/crypto.js +++ b/js/crypto.js @@ -89,7 +89,6 @@ window.textsecure.crypto = new function() { //TODO: fscking type conversion return Promise.resolve({ pubKey: prependVersion(toArrayBuffer(curve25519(priv))), privKey: privKey}); } - } var privToPub = function(privKey, isIdentity) { return testing_only.privToPub(privKey, isIdentity); } @@ -580,8 +579,8 @@ window.textsecure.crypto = new function() { var aes_key = keys.slice(0, 32); var mac_key = keys.slice(32, 64); - var iv = encryptedBin.slice(0, 32); - var ciphertext = encryptedBin.slice(32, encryptedBin.byteLength - 32); + var iv = encryptedBin.slice(0, 16); + var ciphertext = encryptedBin.slice(16, encryptedBin.byteLength - 32); var ivAndCiphertext = encryptedBin.slice(0, encryptedBin.byteLength - 32); var mac = encryptedBin.slice(encryptedBin.byteLength - 32, encryptedBin.byteLength); diff --git a/js/helpers.js b/js/helpers.js index aa9762c9..71cc702a 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -471,7 +471,9 @@ window.textsecure.subscribeToPush = function() { var promises = []; for (var i = 0; i < decrypted.message.attachments.length; i++) promises[i] = handleAttachment(decrypted.message.attachments[i]); - return Promise.all(promises).then(message_callback); + return Promise.all(promises).then(function() { + message_callback(decrypted); + }); }) }).catch(function(e) { console.log("Error handling incoming message: "); diff --git a/js/models/messages.js b/js/models/messages.js index 32876a96..8d1b5640 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -15,10 +15,16 @@ var Whisper = Whisper || {}; comparator: 'timestamp', addIncomingMessage: function(decrypted) { + //TODO: The data in decrypted (from subscribeToPush) should already be cleaned up + var attachments = []; + for (var i = 0; i < decrypted.message.attachments.length; i++) + attachments[i] = "data:" + decrypted.message.attachments[i].contentType + ";base64," + btoa(getString(decrypted.message.attachments[i].decrypted)); + var m = Whisper.Messages.add({ person: decrypted.pushMessage.source, group: decrypted.message.group, body: decrypted.message.body, + attachments: attachments, type: 'incoming', timestamp: decrypted.message.timestamp }); diff --git a/js/views/messages.js b/js/views/messages.js index 0af6bbe5..c9e9ebfe 100644 --- a/js/views/messages.js +++ b/js/views/messages.js @@ -11,6 +11,7 @@ var Whisper = Whisper || {}; this.$el. append($('
'). append($('')). + append($('')). append($('