Make badge count accurate

Previously it would reset when refreshing the inbox. Now it tracks
changes to conversation unreadCounts.

Fixes #200
This commit is contained in:
lilia 2015-03-23 12:35:20 -07:00
parent c4ae7a21d8
commit 6509561795
2 changed files with 13 additions and 2 deletions

View file

@ -30,6 +30,19 @@
});
inbox.on('change:active_at', inbox.sort);
inbox.on('change:unreadCount', function(model, count) {
var prev = model.previous('unreadCount');
if (count < prev) { // decreased
var newUnreadCount = textsecure.storage.getUnencrypted("unreadCount") - (prev - count);
if (newUnreadCount <= 0) {
newUnreadCount = 0;
extension.navigator.setBadgeText("");
} else {
extension.navigator.setBadgeText(newUnreadCount);
}
textsecure.storage.putUnencrypted("unreadCount", newUnreadCount);
}
});
function fetch() {
window.inbox.fetch({

View file

@ -23,7 +23,5 @@
window.location = '/options.html';
} else {
new bg.Whisper.InboxView().$el.prependTo(bg.$('body',document));
bg.textsecure.storage.putUnencrypted("unreadCount", 0);
extension.navigator.setBadgeText("");
}
}());