Rewrite ReplayableErrors

ReplayableErrors make it easy for the frontend to handle identity key
errors by wrapping the necessary steps into one convenient little
replay() callback function.

The frontend remains agnostic to what those steps are. It just calls
replay() once the user has acknowledged the key change.

The protocol layer is responsible for registering the callbacks needed
by the IncomingIdentityKeyError and OutgoingIdentityKeyError.
This commit is contained in:
lilia 2014-12-18 17:50:04 -08:00
parent 14c53ff710
commit 4a401f07f3
8 changed files with 86 additions and 42 deletions

View file

@ -117,11 +117,11 @@ window.textsecure.messaging = function() {
var tryMessageAgain = function(number, encodedMessage, callback) {
//TODO: Wipe identity key!
refreshGroups(number).then(function() {
var message = textsecure.protobuf.PushMessageContent.decode(encodedMessage, 'binary');
textsecure.sendMessage([number], message, callback);
var message = textsecure.protobuf.PushMessageContent.decode(encodedMessage);
textsecure.sendMessageProto([number], message, callback);
});
};
textsecure.replay.registerReplayFunction(tryMessageAgain, textsecure.replay.SEND_MESSAGE);
textsecure.replay.registerFunction(tryMessageAgain, textsecure.replay.Type.SEND_MESSAGE);
var sendMessageProto = function(numbers, message, callback) {
var numbersCompleted = 0;
@ -175,8 +175,7 @@ window.textsecure.messaging = function() {
if (error.message !== "Identity key changed")
registerError(number, "Failed to reload device keys", error);
else {
error = textsecure.replay.createReplayableError("The destination's identity key has changed", "The identity of the destination has changed. This may be malicious, or the destination may have simply reinstalled TextSecure.",
textsecure.replay.SEND_MESSAGE, [number, getString(message.encode())]);
error = new textsecure.OutgoingIdentityKeyError(encodedNumber, message.encode());
registerError(number, "Identity key changed", error);
}
});