Move function declarations out of storage.onready

This commit is contained in:
lilia 2015-09-21 17:05:19 -07:00
parent c8e51563a0
commit 3bf9e36ead

View file

@ -30,19 +30,8 @@
});
});
storage.fetch();
storage.onready(function() {
var SERVER_URL = 'https://textsecure-service-staging.whispersystems.org';
var messageReceiver;
if (textsecure.registration.isDone()) {
init();
}
extension.on('registration_done', function() {
init(true);
});
setUnreadCount(storage.get("unreadCount", 0));
window.getSocketStatus = function() {
if (messageReceiver) {
return messageReceiver.getStatus();
@ -50,10 +39,22 @@
return -1;
}
};
storage.fetch();
storage.onready(function() {
setUnreadCount(storage.get("unreadCount", 0));
if (textsecure.registration.isDone()) {
init();
}
extension.on('registration_done', function() {
init(true);
});
if (open) {
openInbox();
}
});
function init(firstRun) {
window.removeEventListener('online', init);
@ -61,13 +62,12 @@
if (messageReceiver) { messageReceiver.close(); }
var URL = 'https://textsecure-service-staging.whispersystems.org';
var USERNAME = storage.get('number_id');
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 = new textsecure.MessageReceiver(SERVER_URL, USERNAME, PASSWORD, mySignalingKey);
messageReceiver.addEventListener('message', onMessageReceived);
messageReceiver.addEventListener('receipt', onDeliveryReceipt);
messageReceiver.addEventListener('contact', onContactReceived);
@ -235,5 +235,4 @@
console.log('got delivery receipt for unknown message', pushMessage.source, timestamp);
});
}
});
})();