Remove usage of extension.trigger

This trigger function uses chrome's runtime message passing api, which
traverses between different windows in our runtime, but we only trigger
the updateInbox event from the backgroud page, so we don't need to use
that api, which requires some extra cpu/memory overhead.

// FREEBIE
This commit is contained in:
lilia 2015-07-15 14:08:58 -07:00
parent 2ad422afc8
commit 9dfff879b6
4 changed files with 8 additions and 9 deletions

View file

@ -137,13 +137,13 @@
var message = initIncomingMessage(envelope.source, envelope.timestamp.toNumber());
if (e.name === 'IncomingIdentityKeyError') {
message.save({ errors : [e] }).then(function() {
extension.trigger('updateInbox');
updateInbox();
notifyConversation(message);
});
return;
} else if (e.message !== 'Bad MAC') {
message.save({ errors : [ _.pick(e, ['name', 'message'])]}).then(function() {
extension.trigger('updateInbox');
updateInbox();
notifyConversation(message);
});
return;

View file

@ -84,7 +84,7 @@
timestamp : now,
lastMessage : body
}).then(function() {
extension.trigger('updateInbox'); // inbox fetch
updateInbox();
});
var sendFunc;
@ -108,7 +108,7 @@
});
if (keyErrors.length) {
message.save({ errors : keyErrors }).then(function() {
extension.trigger('updateInbox'); // notify frontend listeners
updateInbox();
});
} else {
if (!(errors instanceof Array)) {
@ -188,7 +188,7 @@
_.each(models, function(message) { message.destroy(); });
this.archive();
return this.save().then(function() {
extension.trigger('updateInbox');
updateInbox();
});
},

View file

@ -218,7 +218,7 @@
conversation.save().then(function() {
message.save().then(function() {
extension.trigger('updateInbox'); // inbox fetch
updateInbox();
if (message.isIncoming()) {
notifyConversation(message);
} else {

View file

@ -41,15 +41,14 @@
}
});
function updateInbox() {
window.updateInbox = function() {
conversations.fetchActive().then(function() {
inbox.reset(conversations.filter(function(model) {
return model.get('active_at');
}));
});
}
};
extension.on('updateInbox', updateInbox);
updateInbox();
setUnreadCount(storage.get("unreadCount", 0));