From c16e80c5e400f885f3d4cba0d833e039fe7a82f6 Mon Sep 17 00:00:00 2001 From: lilia Date: Sat, 17 Sep 2016 18:59:22 -0700 Subject: [PATCH] Let key verification view lazy-load keys // FREEBIE --- js/views/conversation_view.js | 19 +++--------- js/views/key_conflict_dialogue_view.js | 22 +++++--------- js/views/key_verification_view.js | 41 ++++++++++++++++++++++---- js/views/message_detail_view.js | 2 +- 4 files changed, 48 insertions(+), 36 deletions(-) diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 27cafb7d..f3414c88 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -196,21 +196,10 @@ verifyIdentity: function() { if (this.model.isPrivate()) { - var their_number = this.model.id; - var our_number = textsecure.storage.user.getNumber(); - textsecure.storage.protocol.loadIdentityKey(their_number).then(function(their_key) { - textsecure.storage.protocol.loadIdentityKey(our_number).then(function(our_key) { - var view = new Whisper.KeyVerificationPanelView({ - model: { - your_number: our_number, - their_number: their_number, - their_key: their_key, - your_key: our_key - } - }); - this.listenBack(view); - }.bind(this)); - }.bind(this)); + var view = new Whisper.KeyVerificationPanelView({ + model: { their_number: this.model.id } + }); + this.listenBack(view); } }, diff --git a/js/views/key_conflict_dialogue_view.js b/js/views/key_conflict_dialogue_view.js index 5fb706f1..9e72dd1c 100644 --- a/js/views/key_conflict_dialogue_view.js +++ b/js/views/key_conflict_dialogue_view.js @@ -12,20 +12,14 @@ initialize: function(options) { this.contact = options.contact; this.conversation = options.conversation; - var our_number = textsecure.storage.user.getNumber(); - textsecure.storage.protocol.loadIdentityKey(our_number).then(function(our_key) { - this.your_key = our_key; - this.render(); - var view = new Whisper.KeyVerificationView({ - model: { - your_number: our_number, - their_number: this.model.number, - their_key : this.model.identityKey, - your_key : our_key - } - }); - view.$el.appendTo(this.$('.keys')); - }.bind(this)); + this.render(); + var view = new Whisper.KeyVerificationView({ + model: { + their_number: this.model.number, + their_key : this.model.identityKey, + } + }); + view.$el.appendTo(this.$('.keys')); }, events: { 'click .showKeys': 'showKeys', diff --git a/js/views/key_verification_view.js b/js/views/key_verification_view.js index 3022ed7c..7141bb29 100644 --- a/js/views/key_verification_view.js +++ b/js/views/key_verification_view.js @@ -37,12 +37,41 @@ className: 'key-verification', templateName: 'key_verification', initialize: function() { - this.render(); - /* - this.$('.securityNumber').append( - new SecurityNumberView({model: this.model}).el - ); - */ + Promise.all([ + this.loadTheirKey(), + this.loadOurKey(), + ]).then(function() { + this.render(); + /* + this.$('.securityNumber').append( + new SecurityNumberView({model: this.model}).el + ); + */ + }.bind(this)); + }, + setOurKey: function(our_key) { + this.model.your_key = our_key; + }, + setTheirKey: function(their_key) { + this.model.their_key = their_key; + }, + loadTheirKey: function() { + if (this.model.their_key) { + return Promise.resolve(this.model.their_key); + } else { + return textsecure.storage.protocol.loadIdentityKey( + this.model.their_number + ).then(this.setTheirKey.bind(this)); + } + }, + loadOurKey: function() { + if (this.model.your_key) { + return Promise.resolve(this.model.your_key); + } else { + return textsecure.storage.protocol.loadIdentityKey( + textsecure.storage.user.getNumber() + ).then(this.setOurKey.bind(this)); + } }, splitKey: function(key) { // key is an array buffer diff --git a/js/views/message_detail_view.js b/js/views/message_detail_view.js index 537f6523..a392babd 100644 --- a/js/views/message_detail_view.js +++ b/js/views/message_detail_view.js @@ -62,7 +62,7 @@ model: conflict, contact: contact, conversation: this.conversation - }).render(); + }); this.$('.conflicts').append(view.el); }, render: function() {