diff --git a/js/conversation_controller.js b/js/conversation_controller.js index e4c5ae63..8602557d 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -13,7 +13,7 @@ var inboxCollection = new (Backbone.Collection.extend({ initialize: function() { this.on('change:active_at', this.sort); - this.on('change:unreadCount', this.updateUnreadCount); + this.on('add remove change:unreadCount', this.updateUnreadCount); this.listenTo(conversations, 'add change:active_at', this.addActive); }, @@ -28,10 +28,13 @@ } }, updateUnreadCount: function(model, count) { - var prev = model.previous('unreadCount') || 0; - var newUnreadCount = storage.get("unreadCount", 0) - (prev - count); - if (newUnreadCount < 0) { newUnreadCount = 0; } - storage.remove("unreadCount"); + var newUnreadCount = _.reduce( + this.map(function(m) { return m.get('unreadCount'); }), + function(item, memo) { + return item + memo; + }, + 0 + ); storage.put("unreadCount", newUnreadCount); setUnreadCount(newUnreadCount); diff --git a/js/panel_controller.js b/js/panel_controller.js index 09a6df0b..efae7ef6 100644 --- a/js/panel_controller.js +++ b/js/panel_controller.js @@ -80,12 +80,12 @@ window.setUnreadCount = function(count) { if (count > 0) { extension.navigator.setBadgeText(count); - if (inboxOpened === true) { + if (inboxOpened === true && appWindow) { appWindow.contentWindow.document.title = "Signal (" + count + ")"; } } else { extension.navigator.setBadgeText(""); - if (inboxOpened === true) { + if (inboxOpened === true && appWindow) { appWindow.contentWindow.document.title = "Signal"; } }