diff --git a/js/background.js b/js/background.js index 9c3b5945713..bc7e168481d 100644 --- a/js/background.js +++ b/js/background.js @@ -21,6 +21,9 @@ // start a background worker for ecc textsecure.startWorker('/js/libsignal-protocol-worker.js'); Whisper.KeyChangeListener.init(textsecure.storage.protocol); + textsecure.storage.protocol.on('removePreKey', function() { + getAccountManager().refreshPreKeys(); + }); extension.onLaunched(function() { console.log('extension launched'); diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index ecce1d29171..59881be20a0 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -136,16 +136,13 @@ removePreKey: function(keyId) { var prekey = new PreKey({id: keyId}); - return Promise.all([ - new Promise(function(resolve) { - getAccountManager().refreshPreKeys().then(resolve); - }), - new Promise(function(resolve) { - prekey.destroy().then(function() { - resolve(); - }); - }) - ]); + this.trigger('removePreKey'); + + return new Promise(function(resolve) { + prekey.destroy().then(function() { + resolve(); + }); + }); }, /* Returns a signed keypair object or undefined */ diff --git a/test/storage_test.js b/test/storage_test.js index e7649a87d8c..18ea913014b 100644 --- a/test/storage_test.js +++ b/test/storage_test.js @@ -91,21 +91,9 @@ describe("SignalProtocolStore", function() { }); }); describe('removePreKey', function() { - var oldGetAccountManager; before(function(done) { - oldGetAccountManager = window.getAccountManager; - window.getAccountManager = function() { - return { - refreshPreKeys: function() { - return Promise.resolve(); - } - }; - }; store.storePreKey(2, testKey).then(done); }); - after(function() { - window.getAccountManager = oldGetAccountManager; - }); it('deletes prekeys', function(done) { store.removePreKey(2, testKey).then(function() { return store.loadPreKey(2).then(function(key) {