Refactor registration event
Make AccountManager into an event target for better separation between app and service-library handling of registration events.
This commit is contained in:
parent
6dcff46e26
commit
7b3b01bdf6
6 changed files with 57 additions and 15 deletions
|
@ -482,6 +482,7 @@
|
|||
<script type='text/javascript' src='js/models/blockedNumbers.js'></script>
|
||||
|
||||
<script type='text/javascript' src='js/chromium.js'></script>
|
||||
<script type='text/javascript' src='js/registration.js'></script>
|
||||
<script type='text/javascript' src='js/expire.js'></script>
|
||||
<script type='text/javascript' src='js/conversation_controller.js'></script>
|
||||
<script type='text/javascript' src='js/panel_controller.js'></script>
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
extension.onLaunched(function() {
|
||||
console.log('extension launched');
|
||||
storage.onready(function() {
|
||||
if (textsecure.registration.everDone()) {
|
||||
if (Whisper.Registration.everDone()) {
|
||||
openInbox();
|
||||
}
|
||||
if (!textsecure.registration.isDone()) {
|
||||
if (!Whisper.Registration.isDone()) {
|
||||
extension.install();
|
||||
}
|
||||
});
|
||||
|
@ -47,7 +47,14 @@
|
|||
window.getAccountManager = function() {
|
||||
var USERNAME = storage.get('number_id');
|
||||
var PASSWORD = storage.get('password');
|
||||
return new textsecure.AccountManager(SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD);
|
||||
var accountManager = new textsecure.AccountManager(
|
||||
SERVER_URL, SERVER_PORTS, USERNAME, PASSWORD
|
||||
);
|
||||
accountManager.addEventListener('registration', function() {
|
||||
Whisper.Registration.markDone();
|
||||
extension.trigger('registration_done');
|
||||
});
|
||||
return accountManager;
|
||||
};
|
||||
|
||||
storage.fetch();
|
||||
|
@ -55,7 +62,7 @@
|
|||
window.dispatchEvent(new Event('storage_ready'));
|
||||
setUnreadCount(storage.get("unreadCount", 0));
|
||||
|
||||
if (textsecure.registration.isDone()) {
|
||||
if (Whisper.Registration.isDone()) {
|
||||
extension.keepAwake();
|
||||
init();
|
||||
}
|
||||
|
@ -76,7 +83,7 @@
|
|||
|
||||
function init(firstRun) {
|
||||
window.removeEventListener('online', init);
|
||||
if (!textsecure.registration.isDone()) { return; }
|
||||
if (!Whisper.Registration.isDone()) { return; }
|
||||
|
||||
if (messageReceiver) { messageReceiver.close(); }
|
||||
|
||||
|
@ -189,7 +196,7 @@
|
|||
console.log(e.stack);
|
||||
|
||||
if (e.name === 'HTTPError' && (e.code == 401 || e.code == 403)) {
|
||||
textsecure.registration.remove();
|
||||
Whisper.Registration.remove();
|
||||
extension.install();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -37886,7 +37886,8 @@ var TextSecureServer = (function() {
|
|||
this.server = new TextSecureServer(url, ports, username, password);
|
||||
}
|
||||
|
||||
AccountManager.prototype = {
|
||||
AccountManager.prototype = new textsecure.EventTarget();
|
||||
AccountManager.prototype.extend({
|
||||
constructor: AccountManager,
|
||||
requestVoiceVerification: function(number) {
|
||||
return this.server.requestVerificationVoice(number);
|
||||
|
@ -37898,16 +37899,18 @@ var TextSecureServer = (function() {
|
|||
var registerKeys = this.server.registerKeys.bind(this.server);
|
||||
var createAccount = this.createAccount.bind(this);
|
||||
var generateKeys = this.generateKeys.bind(this, 100);
|
||||
var registrationDone = this.registrationDone.bind(this);
|
||||
return libsignal.KeyHelper.generateIdentityKeyPair().then(function(identityKeyPair) {
|
||||
return createAccount(number, verificationCode, identityKeyPair).
|
||||
then(generateKeys).
|
||||
then(registerKeys).
|
||||
then(textsecure.registration.done);
|
||||
then(registrationDone);
|
||||
}.bind(this));
|
||||
},
|
||||
registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) {
|
||||
var createAccount = this.createAccount.bind(this);
|
||||
var generateKeys = this.generateKeys.bind(this, 100, progressCallback);
|
||||
var registrationDone = this.registrationDone.bind(this);
|
||||
var registerKeys = this.server.registerKeys.bind(this.server);
|
||||
var getSocket = this.server.getProvisioningSocket.bind(this.server);
|
||||
var provisioningCipher = new libsignal.ProvisioningCipher();
|
||||
|
@ -37954,7 +37957,7 @@ var TextSecureServer = (function() {
|
|||
});
|
||||
}).then(generateKeys).
|
||||
then(registerKeys).
|
||||
then(textsecure.registration.done);
|
||||
then(registrationDone);
|
||||
},
|
||||
refreshPreKeys: function() {
|
||||
var generateKeys = this.generateKeys.bind(this, 100);
|
||||
|
@ -38057,8 +38060,11 @@ var TextSecureServer = (function() {
|
|||
return result;
|
||||
});
|
||||
});
|
||||
},
|
||||
registrationDone: function() {
|
||||
this.dispatchEvent(new Event('registration'));
|
||||
}
|
||||
};
|
||||
});
|
||||
textsecure.AccountManager = AccountManager;
|
||||
|
||||
}());
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
el: $('#install'),
|
||||
deviceName: deviceName
|
||||
});
|
||||
if (bg.textsecure.registration.everDone()) {
|
||||
if (bg.Whisper.Registration.everDone()) {
|
||||
view.selectStep(3);
|
||||
}
|
||||
view.$el.show();
|
||||
|
|
22
js/registration.js
Normal file
22
js/registration.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* vim: ts=4:sw=4:expandtab
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
Whisper.Registration = {
|
||||
markDone: function () {
|
||||
storage.put('chromiumRegistrationDoneEver', '');
|
||||
storage.put('chromiumRegistrationDone', '');
|
||||
},
|
||||
isDone: function () {
|
||||
return storage.get('chromiumRegistrationDone') === '';
|
||||
},
|
||||
everDone: function() {
|
||||
return storage.get('chromiumRegistrationDoneEver') === '' ||
|
||||
storage.get('chromiumRegistrationDone') === '';
|
||||
},
|
||||
remove: function() {
|
||||
storage.remove('chromiumRegistrationDone');
|
||||
}
|
||||
};
|
||||
}());
|
|
@ -11,7 +11,8 @@
|
|||
this.server = new TextSecureServer(url, ports, username, password);
|
||||
}
|
||||
|
||||
AccountManager.prototype = {
|
||||
AccountManager.prototype = new textsecure.EventTarget();
|
||||
AccountManager.prototype.extend({
|
||||
constructor: AccountManager,
|
||||
requestVoiceVerification: function(number) {
|
||||
return this.server.requestVerificationVoice(number);
|
||||
|
@ -23,16 +24,18 @@
|
|||
var registerKeys = this.server.registerKeys.bind(this.server);
|
||||
var createAccount = this.createAccount.bind(this);
|
||||
var generateKeys = this.generateKeys.bind(this, 100);
|
||||
var registrationDone = this.registrationDone.bind(this);
|
||||
return libsignal.KeyHelper.generateIdentityKeyPair().then(function(identityKeyPair) {
|
||||
return createAccount(number, verificationCode, identityKeyPair).
|
||||
then(generateKeys).
|
||||
then(registerKeys).
|
||||
then(textsecure.registration.done);
|
||||
then(registrationDone);
|
||||
}.bind(this));
|
||||
},
|
||||
registerSecondDevice: function(setProvisioningUrl, confirmNumber, progressCallback) {
|
||||
var createAccount = this.createAccount.bind(this);
|
||||
var generateKeys = this.generateKeys.bind(this, 100, progressCallback);
|
||||
var registrationDone = this.registrationDone.bind(this);
|
||||
var registerKeys = this.server.registerKeys.bind(this.server);
|
||||
var getSocket = this.server.getProvisioningSocket.bind(this.server);
|
||||
var provisioningCipher = new libsignal.ProvisioningCipher();
|
||||
|
@ -79,7 +82,7 @@
|
|||
});
|
||||
}).then(generateKeys).
|
||||
then(registerKeys).
|
||||
then(textsecure.registration.done);
|
||||
then(registrationDone);
|
||||
},
|
||||
refreshPreKeys: function() {
|
||||
var generateKeys = this.generateKeys.bind(this, 100);
|
||||
|
@ -182,8 +185,11 @@
|
|||
return result;
|
||||
});
|
||||
});
|
||||
},
|
||||
registrationDone: function() {
|
||||
this.dispatchEvent(new Event('registration'));
|
||||
}
|
||||
};
|
||||
});
|
||||
textsecure.AccountManager = AccountManager;
|
||||
|
||||
}());
|
||||
|
|
Loading…
Reference in a new issue