diff --git a/js/models/conversations.js b/js/models/conversations.js index 90f32524..2a9efb13 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -301,15 +301,16 @@ return textsecure.storage.axolotl.removeIdentityKey(number).then(function() { return textsecure.storage.axolotl.putIdentityKey(number, identityKey).then(function() { - var promises = []; + var promise = Promise.resolve(); this.messageCollection.each(function(message) { if (message.hasKeyConflict(number)) { - promises.push(new Promise(function(resolve) { - resolve(message.resolveConflict(number)); - })); + var resolveConflict = function() { + return message.resolveConflict(number); + }; + promise = promise.then(resolveConflict, resolveConflict); } }); - return promises; + return promise; }.bind(this)); }.bind(this)); }, diff --git a/js/models/messages.js b/js/models/messages.js index 9ed60cb5..8ac31912 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -199,7 +199,6 @@ resolveConflict: function(number) { var error = this.getKeyConflict(number); if (error) { - this.removeConflictFor(number); var promise = new textsecure.ReplayableError(error).replay(); if (this.isIncoming()) { promise = promise.then(function(dataMessage) { @@ -207,6 +206,7 @@ }.bind(this)); } else { promise = promise.then(function() { + this.removeConflictFor(number); this.save(); }.bind(this)); }