From 1e672030de6f52680ae8398dd0a29bd513eabf65 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 22 May 2014 21:59:34 -0700 Subject: [PATCH] Fix a couple things broken in d9bf0a4 Slight revert from said commit. We really do need the IncomingPushMessageSignal protobuf at the UI layer, mostly because it contains the 'source' attribute, without which we don't know who sent the message. Also fix a crash when there are no attachments on a message. --- js/crypto.js | 6 ++++-- js/views/messages.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/js/crypto.js b/js/crypto.js index 79f19702de..a37513f321 100644 --- a/js/crypto.js +++ b/js/crypto.js @@ -603,7 +603,9 @@ window.textsecure.crypto = new function() { case 0: //TYPE_MESSAGE_PLAINTEXT return Promise.resolve(decodePushMessageContentProtobuf(getString(proto.message))); case 1: //TYPE_MESSAGE_CIPHERTEXT - return decryptWhisperMessage(proto.source, getString(proto.message)); + return decryptWhisperMessage(proto.source, getString(proto.message)).then(function(result) { + return {message:result, pushMessage: proto}; + }); case 3: //TYPE_MESSAGE_PREKEY_BUNDLE if (proto.message.readUint8() != (2 << 4 | 2)) throw new Error("Bad version byte"); @@ -612,7 +614,7 @@ window.textsecure.crypto = new function() { return decryptWhisperMessage(proto.source, getString(preKeyProto.message), sessions[0]).then(function(result) { if (sessions[1] !== undefined) crypto_storage.saveSession(proto.source, sessions[1]); - return result; + return {message: result, pushMessage:proto}; }); }); } diff --git a/js/views/messages.js b/js/views/messages.js index c9e9ebfe34..87af474924 100644 --- a/js/views/messages.js +++ b/js/views/messages.js @@ -22,8 +22,10 @@ var Whisper = Whisper || {}; this.$el.find('.message-text').text(this.model.get('body')); var attachments = this.model.get('attachments'); - for (var i = 0; i < attachments.length; i++) - this.$el.find('.message-attachment').append(''); + if (attachments) { + for (var i = 0; i < attachments.length; i++) + this.$el.find('.message-attachment').append(''); + } this.$el.find('.metadata').text(this.formatTimestamp()); return this;