From e88d4d81705d65b6483af336634cd1960539e14c Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 23 Feb 2015 15:12:34 -0800 Subject: [PATCH] Tweak replayable errors 1. Return the value returned by the registered function, to expose the underlying promise to the caller. 2. Stop accepting extra arguments to the replay function. The caller should be able to do what they want with the returned promise instead. 3. Add a timestamp argument to the outgoing case, needed to re-try sending a message. --- js/libtextsecure.js | 13 ++++++------- libtextsecure/errors.js | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index baa1c1d39..4e2410c9d 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -40,31 +40,30 @@ ReplayableError.prototype.constructor = ReplayableError; ReplayableError.prototype.replay = function() { - var args = Array.prototype.slice.call(arguments); - args.shift(); - args = this.args.concat(args); - - registeredFunctions[this.functionCode].apply(window, args); + return registeredFunctions[this.functionCode].apply(window, this.args); }; function IncomingIdentityKeyError(number, message) { ReplayableError.call(this, { functionCode : Type.INIT_SESSION, args : [number, message] + }); this.name = 'IncomingIdentityKeyError'; this.message = "The identity of the sender has changed. This may be malicious, or the sender may have simply reinstalled TextSecure."; + this.number = number.split('.')[0]; } IncomingIdentityKeyError.prototype = new ReplayableError(); IncomingIdentityKeyError.prototype.constructor = IncomingIdentityKeyError; - function OutgoingIdentityKeyError(number, message) { + function OutgoingIdentityKeyError(number, message, timestamp) { ReplayableError.call(this, { functionCode : Type.SEND_MESSAGE, - args : [number, message] + args : [number, message, timestamp] }); this.name = 'OutgoingIdentityKeyError'; this.message = "The identity of the destination has changed. This may be malicious, or the destination may have simply reinstalled TextSecure."; + this.number = number.split('.')[0]; } OutgoingIdentityKeyError.prototype = new ReplayableError(); OutgoingIdentityKeyError.prototype.constructor = OutgoingIdentityKeyError; diff --git a/libtextsecure/errors.js b/libtextsecure/errors.js index 9cd5149be..eda72ec47 100644 --- a/libtextsecure/errors.js +++ b/libtextsecure/errors.js @@ -40,31 +40,30 @@ ReplayableError.prototype.constructor = ReplayableError; ReplayableError.prototype.replay = function() { - var args = Array.prototype.slice.call(arguments); - args.shift(); - args = this.args.concat(args); - - registeredFunctions[this.functionCode].apply(window, args); + return registeredFunctions[this.functionCode].apply(window, this.args); }; function IncomingIdentityKeyError(number, message) { ReplayableError.call(this, { functionCode : Type.INIT_SESSION, args : [number, message] + }); this.name = 'IncomingIdentityKeyError'; this.message = "The identity of the sender has changed. This may be malicious, or the sender may have simply reinstalled TextSecure."; + this.number = number.split('.')[0]; } IncomingIdentityKeyError.prototype = new ReplayableError(); IncomingIdentityKeyError.prototype.constructor = IncomingIdentityKeyError; - function OutgoingIdentityKeyError(number, message) { + function OutgoingIdentityKeyError(number, message, timestamp) { ReplayableError.call(this, { functionCode : Type.SEND_MESSAGE, - args : [number, message] + args : [number, message, timestamp] }); this.name = 'OutgoingIdentityKeyError'; this.message = "The identity of the destination has changed. This may be malicious, or the destination may have simply reinstalled TextSecure."; + this.number = number.split('.')[0]; } OutgoingIdentityKeyError.prototype = new ReplayableError(); OutgoingIdentityKeyError.prototype.constructor = OutgoingIdentityKeyError;