From 3ca511a10a763fedcd9eb6d672357588f3602920 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 24 May 2017 14:50:52 -0700 Subject: [PATCH] Unwrap removeIdentityKey from calls to saveIdentity saveIdentity is now reponsible for determining firstUse, so we must not remove the existing key before updating it. Previously, the implementation provided an extra check against overwritting an existing key, but that should be done via isTrustedIdentity instead. // FREEBIE --- js/models/conversations.js | 38 ++++++++++++++++++------------------- js/signal_protocol_store.js | 10 ++++------ 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index c5b6a2bce1..a005035895 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -504,26 +504,24 @@ throw 'No conflicts to resolve'; } - return textsecure.storage.protocol.removeIdentityKey(number).then(function() { - return textsecure.storage.protocol.saveIdentity(number, identityKey).then(function() { - var promise = Promise.resolve(); - var conflicts = this.messageCollection.filter(function(message) { - return message.hasKeyConflict(number); - }); - // group incoming & outgoing - conflicts = _.groupBy(conflicts, function(m) { return m.get('type'); }); - // sort each group by date and concatenate outgoing after incoming - conflicts = _.flatten([ - _.sortBy(conflicts.incoming, function(m) { return m.get('received_at'); }), - _.sortBy(conflicts.outgoing, function(m) { return m.get('received_at'); }), - ]).forEach(function(message) { - var resolveConflict = function() { - return message.resolveConflict(number); - }; - promise = promise.then(resolveConflict, resolveConflict); - }); - return promise; - }.bind(this)); + return textsecure.storage.protocol.saveIdentity(number, identityKey).then(function() { + var promise = Promise.resolve(); + var conflicts = this.messageCollection.filter(function(message) { + return message.hasKeyConflict(number); + }); + // group incoming & outgoing + conflicts = _.groupBy(conflicts, function(m) { return m.get('type'); }); + // sort each group by date and concatenate outgoing after incoming + conflicts = _.flatten([ + _.sortBy(conflicts.incoming, function(m) { return m.get('received_at'); }), + _.sortBy(conflicts.outgoing, function(m) { return m.get('received_at'); }), + ]).forEach(function(message) { + var resolveConflict = function() { + return message.resolveConflict(number); + }; + promise = promise.then(resolveConflict, resolveConflict); + }); + return promise; }.bind(this)); }, notify: function(message) { diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index a17e381771..b05124d39c 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -293,12 +293,10 @@ if (!oldpublicKey || equalArrayBuffers(oldpublicKey, publicKey)) { resolve(true); } else if (!storage.get('safety-numbers-approval', true)) { - this.removeIdentityKey(identifier).then(function() { - this.saveIdentity(identifier, publicKey).then(function() { - console.log('Key changed for', identifier); - this.trigger('keychange', identifier); - resolve(true); - }.bind(this)); + this.saveIdentity(identifier, publicKey).then(function() { + console.log('Key changed for', identifier); + this.trigger('keychange', identifier); + resolve(true); }.bind(this)); } else { resolve(false);