OutgoingMessage: Reduce the calls to registerError

In some cases, due to promise chaining and error propagation, we were
calling registerError more than once for a given error. This would then
cause the overall callback for the send operation to be called with a
partial set of errors, as well as duplicates.

Note: we do need to find a way to attach identityKey to the
OutgoingIdentityKeyError in the case where it comes directly from the
encrypt() instead of our pre-key operations.

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-06-22 17:36:54 -07:00
parent 30bc3fca3a
commit 116e4d2eeb
2 changed files with 38 additions and 16 deletions

View file

@ -38801,10 +38801,9 @@ OutgoingMessage.prototype = {
} }
return builder.processPreKey(device).catch(function(error) { return builder.processPreKey(device).catch(function(error) {
if (error.message === "Identity key changed") { if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError( error.timestamp = device.timestamp;
number, this.message.toArrayBuffer(), error.originalMessage = this.message.toArrayBuffer();
this.timestamp, device.identityKey); error.identityKey = device.identityKey;
this.registerError(number, "Identity key changed", error);
} }
throw error; throw error;
}.bind(this)); }.bind(this));
@ -38915,9 +38914,12 @@ OutgoingMessage.prototype = {
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
} else if (error.message === "Identity key changed") { } else if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError( error.timestamp = this.timestamp;
number, this.message.toArrayBuffer(), this.timestamp); error.originalMessage = this.message.toArrayBuffer();
this.registerError(number, "Identity key changed", error); // looks like this is an error - we don't have the identity key in this situation!
// but we need it to update the identity key when we get a OutgoingIdentityKeyError
// error.identityKey = ????;
throw error;
} else { } else {
this.registerError(number, "Failed to create or send message", error); this.registerError(number, "Failed to create or send message", error);
} }
@ -38960,7 +38962,16 @@ OutgoingMessage.prototype = {
return this.getKeysForNumber(number, updateDevices) return this.getKeysForNumber(number, updateDevices)
.then(this.reloadDevicesAndSend(number, true)) .then(this.reloadDevicesAndSend(number, true))
.catch(function(error) { .catch(function(error) {
this.registerError(number, "Failed to retreive new device keys for number " + number, error); if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError(
number, error.originalMessage, error.timestamp, error.identityKey
);
this.registerError(number, "Identity key changed", error);
} else {
this.registerError(
number, "Failed to retrieve new device keys for number " + number, error
);
}
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
} }

View file

@ -59,10 +59,9 @@ OutgoingMessage.prototype = {
} }
return builder.processPreKey(device).catch(function(error) { return builder.processPreKey(device).catch(function(error) {
if (error.message === "Identity key changed") { if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError( error.timestamp = device.timestamp;
number, this.message.toArrayBuffer(), error.originalMessage = this.message.toArrayBuffer();
this.timestamp, device.identityKey); error.identityKey = device.identityKey;
this.registerError(number, "Identity key changed", error);
} }
throw error; throw error;
}.bind(this)); }.bind(this));
@ -173,9 +172,12 @@ OutgoingMessage.prototype = {
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
} else if (error.message === "Identity key changed") { } else if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError( error.timestamp = this.timestamp;
number, this.message.toArrayBuffer(), this.timestamp); error.originalMessage = this.message.toArrayBuffer();
this.registerError(number, "Identity key changed", error); // looks like this is an error - we don't have the identity key in this situation!
// but we need it to update the identity key when we get a OutgoingIdentityKeyError
// error.identityKey = ????;
throw error;
} else { } else {
this.registerError(number, "Failed to create or send message", error); this.registerError(number, "Failed to create or send message", error);
} }
@ -218,7 +220,16 @@ OutgoingMessage.prototype = {
return this.getKeysForNumber(number, updateDevices) return this.getKeysForNumber(number, updateDevices)
.then(this.reloadDevicesAndSend(number, true)) .then(this.reloadDevicesAndSend(number, true))
.catch(function(error) { .catch(function(error) {
this.registerError(number, "Failed to retreive new device keys for number " + number, error); if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError(
number, error.originalMessage, error.timestamp, error.identityKey
);
this.registerError(number, "Identity key changed", error);
} else {
this.registerError(
number, "Failed to retrieve new device keys for number " + number, error
);
}
}.bind(this)); }.bind(this));
}.bind(this)); }.bind(this));
} }