From d89c3e8e86eacc9fecb0d692ea52522412231ad3 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 1 Jun 2016 18:41:51 -0700 Subject: [PATCH] Remove devices with no keys // FREEBIE --- js/libtextsecure.js | 8 +++++++- libtextsecure/outgoing_message.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 5895e0f5..5a357521 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38570,7 +38570,13 @@ OutgoingMessage.prototype = { var promise = Promise.resolve(); updateDevices.forEach(function(device) { promise = promise.then(function() { - return this.server.getKeysForNumber(number, device).then(handleResult); + return this.server.getKeysForNumber(number, device).then(handleResult).catch(function(e) { + if (e.name === 'HTTPError' && e.code === 404 && device !== 1) { + return this.removeDeviceIdsForNumber(number, [device]); + } else { + throw e; + } + }.bind(this)); }.bind(this)); }.bind(this)); diff --git a/libtextsecure/outgoing_message.js b/libtextsecure/outgoing_message.js index 0444fb12..cd1cf577 100644 --- a/libtextsecure/outgoing_message.js +++ b/libtextsecure/outgoing_message.js @@ -69,7 +69,13 @@ OutgoingMessage.prototype = { var promise = Promise.resolve(); updateDevices.forEach(function(device) { promise = promise.then(function() { - return this.server.getKeysForNumber(number, device).then(handleResult); + return this.server.getKeysForNumber(number, device).then(handleResult).catch(function(e) { + if (e.name === 'HTTPError' && e.code === 404 && device !== 1) { + return this.removeDeviceIdsForNumber(number, [device]); + } else { + throw e; + } + }.bind(this)); }.bind(this)); }.bind(this));