Process all incoming conflicts before outgoing ones
Fixes a session management problem where, after resolving a conflict with some contact, that contact would get bad mac as a result of us sending them a new prekey message before processing a pending conflicted prekey message received from them earlier. Fixes #806 // FREEBIE
This commit is contained in:
parent
dea8983235
commit
7caecc564d
1 changed files with 14 additions and 7 deletions
|
@ -405,13 +405,20 @@
|
||||||
return textsecure.storage.protocol.removeIdentityKey(number).then(function() {
|
return textsecure.storage.protocol.removeIdentityKey(number).then(function() {
|
||||||
return textsecure.storage.protocol.saveIdentity(number, identityKey).then(function() {
|
return textsecure.storage.protocol.saveIdentity(number, identityKey).then(function() {
|
||||||
var promise = Promise.resolve();
|
var promise = Promise.resolve();
|
||||||
this.messageCollection.each(function(message) {
|
var conflicts = this.messageCollection.filter(function(message) {
|
||||||
if (message.hasKeyConflict(number)) {
|
return message.hasKeyConflict(number);
|
||||||
var resolveConflict = function() {
|
});
|
||||||
return message.resolveConflict(number);
|
// group incoming & outgoing
|
||||||
};
|
conflicts = _.groupBy(conflicts, function(m) { return m.get('type'); });
|
||||||
promise = promise.then(resolveConflict, resolveConflict);
|
// 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;
|
return promise;
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue