DRY up registration event callbacks
This was just a special case of the extension.on/trigger interface.
This commit is contained in:
parent
e68720f07f
commit
5762e59c41
3 changed files with 9 additions and 12 deletions
|
@ -38,6 +38,6 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
textsecure.registration.addListener(init);
|
extension.on('registration_done', init);
|
||||||
init();
|
init();
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -38,7 +38,12 @@
|
||||||
chrome.runtime.sendMessage(null, { name: name, data: object });
|
chrome.runtime.sendMessage(null, { name: name, data: object });
|
||||||
};
|
};
|
||||||
|
|
||||||
window.extension.onMessage = function (name, callback) {
|
window.extension.on = function (name, callback) {
|
||||||
|
// this causes every listener to fire on every message.
|
||||||
|
// if we eventually end up with lots of listeners (lol)
|
||||||
|
// might be worth making a map of 'name' -> [callbacks, ...]
|
||||||
|
// so we can fire a single listener that calls only the necessary
|
||||||
|
// calllbacks for that message name
|
||||||
chrome.runtime.onMessage.addListener(function(e) {
|
chrome.runtime.onMessage.addListener(function(e) {
|
||||||
if (e.name === name) {
|
if (e.name === name) {
|
||||||
callback(e.data);
|
callback(e.data);
|
||||||
|
@ -50,20 +55,12 @@
|
||||||
window.textsecure.registration = {
|
window.textsecure.registration = {
|
||||||
done: function () {
|
done: function () {
|
||||||
localStorage.setItem("chromiumRegistrationDone", "");
|
localStorage.setItem("chromiumRegistrationDone", "");
|
||||||
chrome.runtime.sendMessage('registration_done');
|
extension.trigger('registration_done');
|
||||||
window.location = '/index.html';
|
window.location = '/index.html';
|
||||||
},
|
},
|
||||||
|
|
||||||
isDone: function () {
|
isDone: function () {
|
||||||
return localStorage.getItem("chromiumRegistrationDone") !== null;
|
return localStorage.getItem("chromiumRegistrationDone") !== null;
|
||||||
},
|
},
|
||||||
|
|
||||||
addListener: function (callback) {
|
|
||||||
chrome.runtime.onMessage.addListener(function(message) {
|
|
||||||
if (message === 'registration_done') {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
extension.onMessage('message', function(message) {
|
extension.on('message', function(message) {
|
||||||
this.conversations.fetch({id: message.conversationId}).then(function() {
|
this.conversations.fetch({id: message.conversationId}).then(function() {
|
||||||
this.conversations.get(message.conversationId).fetchMessages();
|
this.conversations.get(message.conversationId).fetchMessages();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
Loading…
Reference in a new issue