From c8e51563a0aceaab94075a5500551215e1824126 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 31 Aug 2015 10:40:25 -0700 Subject: [PATCH] Refactor initial sync codepath to application layer To reduce dependence on the message sending module, AccountManager should send no sync requests itself. --- js/background.js | 13 +++++++++++-- js/libtextsecure.js | 4 +--- libtextsecure/account_manager.js | 4 +--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/js/background.js b/js/background.js index a2a744df..8ff30a57 100644 --- a/js/background.js +++ b/js/background.js @@ -37,7 +37,9 @@ if (textsecure.registration.isDone()) { init(); } - extension.on('registration_done', init); + extension.on('registration_done', function() { + init(true); + }); setUnreadCount(storage.get("unreadCount", 0)); @@ -52,7 +54,8 @@ if (open) { openInbox(); } - function init() { + + function init(firstRun) { window.removeEventListener('online', init); if (!textsecure.registration.isDone()) { return; } @@ -63,6 +66,7 @@ var PASSWORD = storage.get('password'); var mySignalingKey = storage.get('signaling_key'); + // initialize the socket and start listening for messages messageReceiver = new textsecure.MessageReceiver(URL, USERNAME, PASSWORD, mySignalingKey); messageReceiver.addEventListener('message', onMessageReceived); messageReceiver.addEventListener('receipt', onDeliveryReceipt); @@ -72,6 +76,11 @@ messageReceiver.addEventListener('error', onError); messageReceiver.addEventListener('contactsync', onContactSyncComplete); + + if (firstRun === true && textsecure.storage.user.getDeviceId() != '1') { + textsecure.messaging.sendRequestContactSyncMessage(); + textsecure.messaging.sendRequestGroupSyncMessage(); + } } function onContactSyncComplete() { diff --git a/js/libtextsecure.js b/js/libtextsecure.js index cac50585..804eb6be 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -39279,9 +39279,7 @@ TextSecureServer = function () { }).then(function() { return generateKeys(100, progressCallback); }).then(TextSecureServer.registerKeys). - then(textsecure.registration.done). - then(textsecure.messaging.sendRequestContactSyncMessage). - then(textsecure.messaging.sendRequestGroupSyncMessage); + then(textsecure.registration.done); }, refreshPreKeys: function() { return TextSecureServer.getMyKeys().then(function(preKeyCount) { diff --git a/libtextsecure/account_manager.js b/libtextsecure/account_manager.js index 439ffd15..02351560 100644 --- a/libtextsecure/account_manager.js +++ b/libtextsecure/account_manager.js @@ -66,9 +66,7 @@ }).then(function() { return generateKeys(100, progressCallback); }).then(TextSecureServer.registerKeys). - then(textsecure.registration.done). - then(textsecure.messaging.sendRequestContactSyncMessage). - then(textsecure.messaging.sendRequestGroupSyncMessage); + then(textsecure.registration.done); }, refreshPreKeys: function() { return TextSecureServer.getMyKeys().then(function(preKeyCount) {