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({
|
var inboxCollection = new (Backbone.Collection.extend({
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.on('change:active_at', this.sort);
|
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);
|
this.listenTo(conversations, 'add change:active_at', this.addActive);
|
||||||
},
|
},
|
||||||
|
@ -28,10 +28,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateUnreadCount: function(model, count) {
|
updateUnreadCount: function(model, count) {
|
||||||
var prev = model.previous('unreadCount') || 0;
|
var newUnreadCount = _.reduce(
|
||||||
var newUnreadCount = storage.get("unreadCount", 0) - (prev - count);
|
this.map(function(m) { return m.get('unreadCount'); }),
|
||||||
if (newUnreadCount < 0) { newUnreadCount = 0; }
|
function(item, memo) {
|
||||||
storage.remove("unreadCount");
|
return item + memo;
|
||||||
|
},
|
||||||
|
0
|
||||||
|
);
|
||||||
storage.put("unreadCount", newUnreadCount);
|
storage.put("unreadCount", newUnreadCount);
|
||||||
|
|
||||||
setUnreadCount(newUnreadCount);
|
setUnreadCount(newUnreadCount);
|
||||||
|
|
|
@ -80,12 +80,12 @@
|
||||||
window.setUnreadCount = function(count) {
|
window.setUnreadCount = function(count) {
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
extension.navigator.setBadgeText(count);
|
extension.navigator.setBadgeText(count);
|
||||||
if (inboxOpened === true) {
|
if (inboxOpened === true && appWindow) {
|
||||||
appWindow.contentWindow.document.title = "Signal (" + count + ")";
|
appWindow.contentWindow.document.title = "Signal (" + count + ")";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
extension.navigator.setBadgeText("");
|
extension.navigator.setBadgeText("");
|
||||||
if (inboxOpened === true) {
|
if (inboxOpened === true && appWindow) {
|
||||||
appWindow.contentWindow.document.title = "Signal";
|
appWindow.contentWindow.document.title = "Signal";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue