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

@ -126,41 +126,6 @@ window.textsecure.throwHumanError = function(error, type, humanError) {
throw e;
}
window.textsecure.replay = function() {
var self = {};
self.REPLAY_FUNCS = {
SEND_MESSAGE: 1,
INIT_SESSION: 2,
}
var functions = {};
self.registerReplayFunction = function(func, functionCode) {
functions[functionCode] = func;
}
self.replayError = function(replayData) {
var args = Array.prototype.slice.call(arguments);
args.shift();
args = replayData.args.concat(args);
functions[replayData.replayFunction].apply(window, args);
}
self.createReplayableError = function(shortMsg, longMsg, replayFunction, args) {
var e = new Error(shortMsg);
e.name = "ReplayableError";
e.humanError = e.longMessage = longMsg;
e.replayData = { replayFunction: replayFunction, args: args };
e.replay = function() {
self.replayError(e.replayData);
}
return e;
}
return self;
}();
// message_callback({message: decryptedMessage, pushMessage: server-providedPushMessage})
window.textsecure.subscribeToPush = function(message_callback) {
var socket = textsecure.api.getMessageWebsocket();