Derive global unread count from individual counts
// FREEBIE
This commit is contained in:
parent
781ada64ca
commit
1be45f3775
2 changed files with 10 additions and 7 deletions
|
@ -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);
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue