From aa421394776bdab13e472821c1f1b957d0075ebd Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 15 Sep 2016 12:11:42 -0700 Subject: [PATCH] Implement non blocking option // FREEBIE --- js/signal_protocol_store.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index 7c9776258..c8d42616c 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -261,9 +261,26 @@ var identityKey = new IdentityKey({id: number}); identityKey.fetch().always(function() { var oldpublicKey = identityKey.get('publicKey'); - resolve(!oldpublicKey || equalArrayBuffers(oldpublicKey, publicKey)); - }); - }); + var matches = equalArrayBuffers(oldpublicKey, publicKey); + var changed = !!oldpublicKey && !matches; + if (changed) { + console.log('Key changed for', identifier); + this.trigger('keychange', identifier); + } + var trusted = !oldpublicKey || matches; + if (trusted) { + resolve(true); + } else if (!storage.get('safety-numbers-approval', true)) { + this.removeIdentityKey(identifier).then(function() { + this.saveIdentity(identifier, publicKey).then(function() { + resolve(true); + }); + }.bind(this)); + } else { + resolve(false); + } + }.bind(this)); + }.bind(this)); }, loadIdentityKey: function(identifier) { if (identifier === null || identifier === undefined) {