Add replayable network errors
Support for manual message retry. // FREEBIE
This commit is contained in:
parent
bc03bdbfc4
commit
fbb65d1988
4 changed files with 60 additions and 2 deletions
|
@ -9,6 +9,7 @@
|
||||||
var Type = {
|
var Type = {
|
||||||
SEND_MESSAGE: 1,
|
SEND_MESSAGE: 1,
|
||||||
INIT_SESSION: 2,
|
INIT_SESSION: 2,
|
||||||
|
NETWORK_REQUEST: 3,
|
||||||
};
|
};
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
window.textsecure.replay = {
|
window.textsecure.replay = {
|
||||||
|
@ -58,6 +59,20 @@
|
||||||
OutgoingIdentityKeyError.prototype = new ReplayableError();
|
OutgoingIdentityKeyError.prototype = new ReplayableError();
|
||||||
OutgoingIdentityKeyError.prototype.constructor = OutgoingIdentityKeyError;
|
OutgoingIdentityKeyError.prototype.constructor = OutgoingIdentityKeyError;
|
||||||
|
|
||||||
|
function NetworkError(number, jsonData, legacy, code) {
|
||||||
|
ReplayableError.call(this, {
|
||||||
|
functionCode : Type.NETWORK_REQUEST,
|
||||||
|
args : [number, jsonData, legacy]
|
||||||
|
});
|
||||||
|
this.name = 'NetworkError';
|
||||||
|
this.message = 'Network request failed'
|
||||||
|
this.code = code;
|
||||||
|
this.number = number;
|
||||||
|
}
|
||||||
|
NetworkError.prototype = new ReplayableError();
|
||||||
|
NetworkError.prototype.constructor = NetworkError;
|
||||||
|
|
||||||
|
window.textsecure.NetworkError = NetworkError;
|
||||||
window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError;
|
window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError;
|
||||||
window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError;
|
window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError;
|
||||||
window.textsecure.ReplayableError = ReplayableError;
|
window.textsecure.ReplayableError = ReplayableError;
|
||||||
|
@ -39618,10 +39633,19 @@ MessageSender.prototype = {
|
||||||
});
|
});
|
||||||
})).then(function(jsonData) {
|
})).then(function(jsonData) {
|
||||||
var legacy = (message instanceof textsecure.protobuf.DataMessage);
|
var legacy = (message instanceof textsecure.protobuf.DataMessage);
|
||||||
return this.server.sendMessages(number, jsonData, legacy);
|
return this.sendRequest(number, jsonData, legacy);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sendRequest: function(number, jsonData, legacy) {
|
||||||
|
return this.server.sendMessages(number, jsonData, legacy).catch(function(e) {
|
||||||
|
if (e.name === 'HTTPError' && e.code === -1) {
|
||||||
|
throw new NetworkError(number, jsonData, legacy);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
makeAttachmentPointer: function(attachment) {
|
makeAttachmentPointer: function(attachment) {
|
||||||
if (typeof attachment !== 'object' || attachment == null) {
|
if (typeof attachment !== 'object' || attachment == null) {
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
|
@ -40005,6 +40029,7 @@ window.textsecure = window.textsecure || {};
|
||||||
textsecure.MessageSender = function(url, username, password) {
|
textsecure.MessageSender = function(url, username, password) {
|
||||||
var sender = new MessageSender(url, username, password);
|
var sender = new MessageSender(url, username, password);
|
||||||
textsecure.replay.registerFunction(sender.tryMessageAgain.bind(sender), textsecure.replay.Type.SEND_MESSAGE);
|
textsecure.replay.registerFunction(sender.tryMessageAgain.bind(sender), textsecure.replay.Type.SEND_MESSAGE);
|
||||||
|
textsecure.replay.registerFunction(sender.sendRequest.bind(sender), textsecure.replay.Type.NETWORK_REQUEST);
|
||||||
|
|
||||||
this.sendRequestGroupSyncMessage = sender.sendRequestGroupSyncMessage .bind(sender);
|
this.sendRequestGroupSyncMessage = sender.sendRequestGroupSyncMessage .bind(sender);
|
||||||
this.sendRequestContactSyncMessage = sender.sendRequestContactSyncMessage.bind(sender);
|
this.sendRequestContactSyncMessage = sender.sendRequestContactSyncMessage.bind(sender);
|
||||||
|
|
|
@ -165,6 +165,14 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
resend: function(number) {
|
||||||
|
var error = this.getSendError(number);
|
||||||
|
if (error) {
|
||||||
|
var promise = new textsecure.ReplayableError(error).replay();
|
||||||
|
this.send(promise);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
resolveConflict: function(number) {
|
resolveConflict: function(number) {
|
||||||
var error = this.getKeyConflict(number);
|
var error = this.getKeyConflict(number);
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
var Type = {
|
var Type = {
|
||||||
SEND_MESSAGE: 1,
|
SEND_MESSAGE: 1,
|
||||||
INIT_SESSION: 2,
|
INIT_SESSION: 2,
|
||||||
|
NETWORK_REQUEST: 3,
|
||||||
};
|
};
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
window.textsecure.replay = {
|
window.textsecure.replay = {
|
||||||
|
@ -57,6 +58,20 @@
|
||||||
OutgoingIdentityKeyError.prototype = new ReplayableError();
|
OutgoingIdentityKeyError.prototype = new ReplayableError();
|
||||||
OutgoingIdentityKeyError.prototype.constructor = OutgoingIdentityKeyError;
|
OutgoingIdentityKeyError.prototype.constructor = OutgoingIdentityKeyError;
|
||||||
|
|
||||||
|
function NetworkError(number, jsonData, legacy, code) {
|
||||||
|
ReplayableError.call(this, {
|
||||||
|
functionCode : Type.NETWORK_REQUEST,
|
||||||
|
args : [number, jsonData, legacy]
|
||||||
|
});
|
||||||
|
this.name = 'NetworkError';
|
||||||
|
this.message = 'Network request failed'
|
||||||
|
this.code = code;
|
||||||
|
this.number = number;
|
||||||
|
}
|
||||||
|
NetworkError.prototype = new ReplayableError();
|
||||||
|
NetworkError.prototype.constructor = NetworkError;
|
||||||
|
|
||||||
|
window.textsecure.NetworkError = NetworkError;
|
||||||
window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError;
|
window.textsecure.IncomingIdentityKeyError = IncomingIdentityKeyError;
|
||||||
window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError;
|
window.textsecure.OutgoingIdentityKeyError = OutgoingIdentityKeyError;
|
||||||
window.textsecure.ReplayableError = ReplayableError;
|
window.textsecure.ReplayableError = ReplayableError;
|
||||||
|
|
|
@ -37,10 +37,19 @@ MessageSender.prototype = {
|
||||||
});
|
});
|
||||||
})).then(function(jsonData) {
|
})).then(function(jsonData) {
|
||||||
var legacy = (message instanceof textsecure.protobuf.DataMessage);
|
var legacy = (message instanceof textsecure.protobuf.DataMessage);
|
||||||
return this.server.sendMessages(number, jsonData, legacy);
|
return this.sendRequest(number, jsonData, legacy);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sendRequest: function(number, jsonData, legacy) {
|
||||||
|
return this.server.sendMessages(number, jsonData, legacy).catch(function(e) {
|
||||||
|
if (e.name === 'HTTPError' && e.code === -1) {
|
||||||
|
throw new NetworkError(number, jsonData, legacy);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
makeAttachmentPointer: function(attachment) {
|
makeAttachmentPointer: function(attachment) {
|
||||||
if (typeof attachment !== 'object' || attachment == null) {
|
if (typeof attachment !== 'object' || attachment == null) {
|
||||||
return Promise.resolve(undefined);
|
return Promise.resolve(undefined);
|
||||||
|
@ -424,6 +433,7 @@ window.textsecure = window.textsecure || {};
|
||||||
textsecure.MessageSender = function(url, username, password) {
|
textsecure.MessageSender = function(url, username, password) {
|
||||||
var sender = new MessageSender(url, username, password);
|
var sender = new MessageSender(url, username, password);
|
||||||
textsecure.replay.registerFunction(sender.tryMessageAgain.bind(sender), textsecure.replay.Type.SEND_MESSAGE);
|
textsecure.replay.registerFunction(sender.tryMessageAgain.bind(sender), textsecure.replay.Type.SEND_MESSAGE);
|
||||||
|
textsecure.replay.registerFunction(sender.sendRequest.bind(sender), textsecure.replay.Type.NETWORK_REQUEST);
|
||||||
|
|
||||||
this.sendRequestGroupSyncMessage = sender.sendRequestGroupSyncMessage .bind(sender);
|
this.sendRequestGroupSyncMessage = sender.sendRequestGroupSyncMessage .bind(sender);
|
||||||
this.sendRequestContactSyncMessage = sender.sendRequestContactSyncMessage.bind(sender);
|
this.sendRequestContactSyncMessage = sender.sendRequestContactSyncMessage.bind(sender);
|
||||||
|
|
Loading…
Add table
Reference in a new issue