From a960acacc609a50d9939f231917b01a5a9ba9a4f Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 28 Apr 2015 16:26:41 -0700 Subject: [PATCH] Add textsecure.refreshKeys This helper checks the server for the number of remaining prekeys, then generates more if there are fewer than 10 remaining. // FREEBIE --- js/libtextsecure.js | 18 ++++++++++++++++++ libtextsecure/api.js | 10 ++++++++++ libtextsecure/helpers.js | 8 ++++++++ 3 files changed, 36 insertions(+) diff --git a/js/libtextsecure.js b/js/libtextsecure.js index 5b8d73051..9d43f6101 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38913,6 +38913,14 @@ textsecure.processDecrypted = function(decrypted, source) { }); }; +window.textsecure.refreshPreKeys = function() { + return textsecure.api.getMyKeys().then(function(preKeyCount) { + if (preKeyCount < 10) { + generateKeys(); + } + }); +}; + function createAccount(number, verificationCode, identityKeyPair, single_device) { textsecure.storage.put('identityKey', identityKeyPair); @@ -39331,6 +39339,16 @@ window.textsecure.api = function () { }); }; + self.getMyKeys = function(number, deviceId) { + return doAjax({ + call : 'keys', + httpType : 'GET', + do_auth : true, + }).then(function(res) { + return parseInt(res.count); + }); + }; + self.getKeysForNumber = function(number, deviceId) { if (deviceId === undefined) deviceId = "*"; diff --git a/libtextsecure/api.js b/libtextsecure/api.js index 526aac625..958ba4201 100644 --- a/libtextsecure/api.js +++ b/libtextsecure/api.js @@ -216,6 +216,16 @@ window.textsecure.api = function () { }); }; + self.getMyKeys = function(number, deviceId) { + return doAjax({ + call : 'keys', + httpType : 'GET', + do_auth : true, + }).then(function(res) { + return parseInt(res.count); + }); + }; + self.getKeysForNumber = function(number, deviceId) { if (deviceId === undefined) deviceId = "*"; diff --git a/libtextsecure/helpers.js b/libtextsecure/helpers.js index 081b719eb..b881dc261 100644 --- a/libtextsecure/helpers.js +++ b/libtextsecure/helpers.js @@ -248,6 +248,14 @@ textsecure.processDecrypted = function(decrypted, source) { }); }; +window.textsecure.refreshPreKeys = function() { + return textsecure.api.getMyKeys().then(function(preKeyCount) { + if (preKeyCount < 10) { + generateKeys(); + } + }); +}; + function createAccount(number, verificationCode, identityKeyPair, single_device) { textsecure.storage.put('identityKey', identityKeyPair);