Refactor initial sync codepath to application layer
To reduce dependence on the message sending module, AccountManager should send no sync requests itself.
This commit is contained in:
parent
6123c419d0
commit
c8e51563a0
3 changed files with 13 additions and 8 deletions
|
@ -37,7 +37,9 @@
|
||||||
if (textsecure.registration.isDone()) {
|
if (textsecure.registration.isDone()) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
extension.on('registration_done', init);
|
extension.on('registration_done', function() {
|
||||||
|
init(true);
|
||||||
|
});
|
||||||
|
|
||||||
setUnreadCount(storage.get("unreadCount", 0));
|
setUnreadCount(storage.get("unreadCount", 0));
|
||||||
|
|
||||||
|
@ -52,7 +54,8 @@
|
||||||
if (open) {
|
if (open) {
|
||||||
openInbox();
|
openInbox();
|
||||||
}
|
}
|
||||||
function init() {
|
|
||||||
|
function init(firstRun) {
|
||||||
window.removeEventListener('online', init);
|
window.removeEventListener('online', init);
|
||||||
if (!textsecure.registration.isDone()) { return; }
|
if (!textsecure.registration.isDone()) { return; }
|
||||||
|
|
||||||
|
@ -63,6 +66,7 @@
|
||||||
var PASSWORD = storage.get('password');
|
var PASSWORD = storage.get('password');
|
||||||
var mySignalingKey = storage.get('signaling_key');
|
var mySignalingKey = storage.get('signaling_key');
|
||||||
|
|
||||||
|
// initialize the socket and start listening for messages
|
||||||
messageReceiver = new textsecure.MessageReceiver(URL, USERNAME, PASSWORD, mySignalingKey);
|
messageReceiver = new textsecure.MessageReceiver(URL, USERNAME, PASSWORD, mySignalingKey);
|
||||||
messageReceiver.addEventListener('message', onMessageReceived);
|
messageReceiver.addEventListener('message', onMessageReceived);
|
||||||
messageReceiver.addEventListener('receipt', onDeliveryReceipt);
|
messageReceiver.addEventListener('receipt', onDeliveryReceipt);
|
||||||
|
@ -72,6 +76,11 @@
|
||||||
messageReceiver.addEventListener('error', onError);
|
messageReceiver.addEventListener('error', onError);
|
||||||
|
|
||||||
messageReceiver.addEventListener('contactsync', onContactSyncComplete);
|
messageReceiver.addEventListener('contactsync', onContactSyncComplete);
|
||||||
|
|
||||||
|
if (firstRun === true && textsecure.storage.user.getDeviceId() != '1') {
|
||||||
|
textsecure.messaging.sendRequestContactSyncMessage();
|
||||||
|
textsecure.messaging.sendRequestGroupSyncMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onContactSyncComplete() {
|
function onContactSyncComplete() {
|
||||||
|
|
|
@ -39279,9 +39279,7 @@ TextSecureServer = function () {
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return generateKeys(100, progressCallback);
|
return generateKeys(100, progressCallback);
|
||||||
}).then(TextSecureServer.registerKeys).
|
}).then(TextSecureServer.registerKeys).
|
||||||
then(textsecure.registration.done).
|
then(textsecure.registration.done);
|
||||||
then(textsecure.messaging.sendRequestContactSyncMessage).
|
|
||||||
then(textsecure.messaging.sendRequestGroupSyncMessage);
|
|
||||||
},
|
},
|
||||||
refreshPreKeys: function() {
|
refreshPreKeys: function() {
|
||||||
return TextSecureServer.getMyKeys().then(function(preKeyCount) {
|
return TextSecureServer.getMyKeys().then(function(preKeyCount) {
|
||||||
|
|
|
@ -66,9 +66,7 @@
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return generateKeys(100, progressCallback);
|
return generateKeys(100, progressCallback);
|
||||||
}).then(TextSecureServer.registerKeys).
|
}).then(TextSecureServer.registerKeys).
|
||||||
then(textsecure.registration.done).
|
then(textsecure.registration.done);
|
||||||
then(textsecure.messaging.sendRequestContactSyncMessage).
|
|
||||||
then(textsecure.messaging.sendRequestGroupSyncMessage);
|
|
||||||
},
|
},
|
||||||
refreshPreKeys: function() {
|
refreshPreKeys: function() {
|
||||||
return TextSecureServer.getMyKeys().then(function(preKeyCount) {
|
return TextSecureServer.getMyKeys().then(function(preKeyCount) {
|
||||||
|
|
Loading…
Reference in a new issue