Skip to content

Commit

Permalink
OutgoingMessage: Reduce the calls to registerError
Browse files Browse the repository at this point in the history
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
  • Loading branch information
scottnonnenberg committed Aug 4, 2017
1 parent 30bc3fc commit 116e4d2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
27 changes: 19 additions & 8 deletions js/libtextsecure.js
Expand Up @@ -38801,10 +38801,9 @@ OutgoingMessage.prototype = {
}
return builder.processPreKey(device).catch(function(error) {
if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError(
number, this.message.toArrayBuffer(),
this.timestamp, device.identityKey);
this.registerError(number, "Identity key changed", error);
error.timestamp = device.timestamp;
error.originalMessage = this.message.toArrayBuffer();
error.identityKey = device.identityKey;
}
throw error;
}.bind(this));
Expand Down Expand Up @@ -38915,9 +38914,12 @@ OutgoingMessage.prototype = {
}.bind(this));
}.bind(this));
} else if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError(
number, this.message.toArrayBuffer(), this.timestamp);
this.registerError(number, "Identity key changed", error);
error.timestamp = this.timestamp;
error.originalMessage = this.message.toArrayBuffer();
// 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 {
this.registerError(number, "Failed to create or send message", error);
}
Expand Down Expand Up @@ -38960,7 +38962,16 @@ OutgoingMessage.prototype = {
return this.getKeysForNumber(number, updateDevices)
.then(this.reloadDevicesAndSend(number, true))
.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));
}
Expand Down
27 changes: 19 additions & 8 deletions libtextsecure/outgoing_message.js
Expand Up @@ -59,10 +59,9 @@ OutgoingMessage.prototype = {
}
return builder.processPreKey(device).catch(function(error) {
if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError(
number, this.message.toArrayBuffer(),
this.timestamp, device.identityKey);
this.registerError(number, "Identity key changed", error);
error.timestamp = device.timestamp;
error.originalMessage = this.message.toArrayBuffer();
error.identityKey = device.identityKey;
}
throw error;
}.bind(this));
Expand Down Expand Up @@ -173,9 +172,12 @@ OutgoingMessage.prototype = {
}.bind(this));
}.bind(this));
} else if (error.message === "Identity key changed") {
error = new textsecure.OutgoingIdentityKeyError(
number, this.message.toArrayBuffer(), this.timestamp);
this.registerError(number, "Identity key changed", error);
error.timestamp = this.timestamp;
error.originalMessage = this.message.toArrayBuffer();
// 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 {
this.registerError(number, "Failed to create or send message", error);
}
Expand Down Expand Up @@ -218,7 +220,16 @@ OutgoingMessage.prototype = {
return this.getKeysForNumber(number, updateDevices)
.then(this.reloadDevicesAndSend(number, true))
.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));
}
Expand Down

0 comments on commit 116e4d2

Please sign in to comment.