From 38a830c56169450ed0505d4a7e68769fdd521881 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 20 Feb 2017 20:11:41 -0800 Subject: [PATCH] Fixup account manager task queue Such that it still pumps tasks if one of them throws/rejects. // FREEBIE --- js/libtextsecure.js | 16 +++++++--------- libtextsecure/account_manager.js | 16 +++++++--------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index b60833fd..6792da71 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -37946,7 +37946,7 @@ var TextSecureServer = (function() { var createAccount = this.createAccount.bind(this); var generateKeys = this.generateKeys.bind(this, 100); var registrationDone = this.registrationDone.bind(this); - this.pending = this.pending.then(function() { + return this.queueTask(function() { return libsignal.KeyHelper.generateIdentityKeyPair().then(function(identityKeyPair) { return createAccount(number, verificationCode, identityKeyPair). then(generateKeys). @@ -37954,8 +37954,6 @@ var TextSecureServer = (function() { then(registrationDone); }.bind(this)); }.bind(this)); - - return this.pending; }, registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) { var createAccount = this.createAccount.bind(this); @@ -37963,7 +37961,7 @@ var TextSecureServer = (function() { var registrationDone = this.registrationDone.bind(this); var registerKeys = this.server.registerKeys.bind(this.server); var getSocket = this.server.getProvisioningSocket.bind(this.server); - this.pending = this.pending.then(function() { + return this.queueTask(function() { var provisioningCipher = new libsignal.ProvisioningCipher(); return provisioningCipher.getPublicKey().then(function(pubKey) { return new Promise(function(resolve, reject) { @@ -38010,13 +38008,12 @@ var TextSecureServer = (function() { then(registerKeys). then(registrationDone); }.bind(this)); - return this.pending; }, refreshPreKeys: function() { var generateKeys = this.generateKeys.bind(this, 100); var registerKeys = this.server.registerKeys.bind(this.server); - this.pending = this.pending.then(function() { + return this.queueTask(function() { return this.server.getMyKeys().then(function(preKeyCount) { console.log('prekey count ' + preKeyCount); if (preKeyCount < 10) { @@ -38024,10 +38021,9 @@ var TextSecureServer = (function() { } }.bind(this)); }.bind(this)); - return this.pending; }, rotateSignedPreKey: function() { - this.pending = this.pending.then(function() { + return this.queueTask(function() { var signedKeyId = textsecure.storage.get('signedKeyId', 1); if (typeof signedKeyId != 'number') { @@ -38058,7 +38054,9 @@ var TextSecureServer = (function() { }); }); }.bind(this)); - return this.pending; + }, + queueTask: function(task) { + return this.pending = this.pending.then(task, task); }, cleanSignedPreKeys: function() { var nextSignedKeyId = textsecure.storage.get('signedKeyId'); diff --git a/libtextsecure/account_manager.js b/libtextsecure/account_manager.js index 0a1bef6f..4edd9937 100644 --- a/libtextsecure/account_manager.js +++ b/libtextsecure/account_manager.js @@ -28,7 +28,7 @@ var createAccount = this.createAccount.bind(this); var generateKeys = this.generateKeys.bind(this, 100); var registrationDone = this.registrationDone.bind(this); - this.pending = this.pending.then(function() { + return this.queueTask(function() { return libsignal.KeyHelper.generateIdentityKeyPair().then(function(identityKeyPair) { return createAccount(number, verificationCode, identityKeyPair). then(generateKeys). @@ -36,8 +36,6 @@ then(registrationDone); }.bind(this)); }.bind(this)); - - return this.pending; }, registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) { var createAccount = this.createAccount.bind(this); @@ -45,7 +43,7 @@ var registrationDone = this.registrationDone.bind(this); var registerKeys = this.server.registerKeys.bind(this.server); var getSocket = this.server.getProvisioningSocket.bind(this.server); - this.pending = this.pending.then(function() { + return this.queueTask(function() { var provisioningCipher = new libsignal.ProvisioningCipher(); return provisioningCipher.getPublicKey().then(function(pubKey) { return new Promise(function(resolve, reject) { @@ -92,13 +90,12 @@ then(registerKeys). then(registrationDone); }.bind(this)); - return this.pending; }, refreshPreKeys: function() { var generateKeys = this.generateKeys.bind(this, 100); var registerKeys = this.server.registerKeys.bind(this.server); - this.pending = this.pending.then(function() { + return this.queueTask(function() { return this.server.getMyKeys().then(function(preKeyCount) { console.log('prekey count ' + preKeyCount); if (preKeyCount < 10) { @@ -106,10 +103,9 @@ } }.bind(this)); }.bind(this)); - return this.pending; }, rotateSignedPreKey: function() { - this.pending = this.pending.then(function() { + return this.queueTask(function() { var signedKeyId = textsecure.storage.get('signedKeyId', 1); if (typeof signedKeyId != 'number') { @@ -140,7 +136,9 @@ }); }); }.bind(this)); - return this.pending; + }, + queueTask: function(task) { + return this.pending = this.pending.then(task, task); }, cleanSignedPreKeys: function() { var nextSignedKeyId = textsecure.storage.get('signedKeyId');