Update identity key after a send error tells us it has changed

FREEBIE
pull/749/head
Scott Nonnenberg 8 years ago
parent 22208ec3f8
commit 5e62d0cfd8

@ -46,6 +46,7 @@
}); });
this.messageCollection.on('change:errors', this.handleMessageError, this); this.messageCollection.on('change:errors', this.handleMessageError, this);
this.messageCollection.on('send-error', this.onMessageError, this);
this.on('change:avatar', this.updateAvatarUrl); this.on('change:avatar', this.updateAvatarUrl);
this.on('destroy', this.revokeAvatarUrl); this.on('destroy', this.revokeAvatarUrl);
@ -55,6 +56,9 @@
return this.id === this.ourNumber; return this.id === this.ourNumber;
}, },
onMessageError: function() {
this.updateVerified();
},
updateVerified: function() { updateVerified: function() {
if (this.isPrivate()) { if (this.isPrivate()) {
return Promise.all([ return Promise.all([

@ -211,15 +211,6 @@
} }
this.save({sent: true, expirationStartTimestamp: now}); this.save({sent: true, expirationStartTimestamp: now});
this.sendSyncMessage(); this.sendSyncMessage();
// var error = new Error('OutgoingIdentityKeyError');
// error.name = 'OutgoingIdentityKeyError';
// error.number = result.successfulNumbers[0];
// throw error;
// var error = new Error('OutgoingMessageError');
// error.name = 'OutgoingMessageError';
// throw error;
}.bind(this)).catch(function(result) { }.bind(this)).catch(function(result) {
var now = Date.now(); var now = Date.now();
this.trigger('done'); this.trigger('done');
@ -227,19 +218,36 @@
this.set({dataMessage: result.dataMessage}); this.set({dataMessage: result.dataMessage});
} }
var promises = [];
if (result instanceof Error) { if (result instanceof Error) {
this.saveErrors(result); this.saveErrors(result);
if (result.name === 'SignedPreKeyRotationError') { if (result.name === 'SignedPreKeyRotationError') {
getAccountManager().rotateSignedPreKey(); return getAccountManager().rotateSignedPreKey();
}
else if (result.name === 'OutgoingIdentityKeyError') {
promises.push(textsecure.storage.protocol.saveIdentity(
result.number, result.identityKey, false
));
} }
} else { } else {
this.saveErrors(result.errors); this.saveErrors(result.errors);
if (result.successfulNumbers.length > 0) { if (result.successfulNumbers.length > 0) {
this.set({sent: true, expirationStartTimestamp: now}); this.set({sent: true, expirationStartTimestamp: now});
this.sendSyncMessage(); promises.push(this.sendSyncMessage());
} }
promises = promises.concat(_.map(result.errors, function(error) {
if (error.name === 'OutgoingIdentityKeyError') {
return textsecure.storage.protocol.saveIdentity(
error.number, error.identityKey, false
);
}
}));
} }
return Promise.all(promises).then(function() {
this.trigger('send-error', this.get('errors'));
}.bind(this));
}.bind(this)); }.bind(this));
}, },

Loading…
Cancel
Save