From 08878b3dc8548b8fb648ef6a441def69d577106f Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 20 May 2015 13:04:16 -0700 Subject: [PATCH] Update inbox after sending a message Also change the event name to reflect how its being used, and stop passing the message object around since it is not being used. // FREEBIE --- js/background.js | 4 ++-- js/inbox_controller.js | 2 +- js/models/conversations.js | 4 +++- js/models/messages.js | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/js/background.js b/js/background.js index 23fe378b..f0b2c535 100644 --- a/js/background.js +++ b/js/background.js @@ -84,12 +84,12 @@ }).catch(function(e) { if (e.name === 'IncomingIdentityKeyError') { message.save({ errors : [e] }).then(function() { - extension.trigger('message', message); + extension.trigger('updateInbox'); notifyConversation(message); }); } else if (e.message === 'Bad MAC') { message.save({ errors : [ _.pick(e, ['name', 'message'])]}).then(function() { - extension.trigger('message', message); + extension.trigger('updateInbox'); notifyConversation(message); }); } else { diff --git a/js/inbox_controller.js b/js/inbox_controller.js index 17402ad3..58fbc9ac 100644 --- a/js/inbox_controller.js +++ b/js/inbox_controller.js @@ -50,7 +50,7 @@ }); } - extension.on('message', fetch); + extension.on('updateInbox', fetch); fetch(); setUnreadCount(storage.get("unreadCount", 0)); diff --git a/js/models/conversations.js b/js/models/conversations.js index 0dc06234..18090e3f 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -84,6 +84,8 @@ active_at : now, timestamp : now, lastMessage : body + }).then(function() { + extension.trigger('updateInbox'); // inbox fetch }); var sendFunc; @@ -102,7 +104,7 @@ }); if (keyErrors.length) { message.save({ errors : keyErrors }).then(function() { - extension.trigger('message', message); // notify frontend listeners + extension.trigger('updateInbox'); // notify frontend listeners }); } else { if (!(errors instanceof Array)) { diff --git a/js/models/messages.js b/js/models/messages.js index dcd1149e..269475b0 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -228,7 +228,7 @@ conversation.save().then(function() { message.save().then(function() { - extension.trigger('message', message); // inbox fetch + extension.trigger('updateInbox'); // inbox fetch if (message.isIncoming()) { notifyConversation(message); } else {