From 6509561795a9388023615ff664af32089cf8d33a Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 23 Mar 2015 12:35:20 -0700 Subject: [PATCH] Make badge count accurate Previously it would reset when refreshing the inbox. Now it tracks changes to conversation unreadCounts. Fixes #200 --- js/inbox_controller.js | 13 +++++++++++++ js/index.js | 2 -- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/js/inbox_controller.js b/js/inbox_controller.js index 77dfa22e97d..a19da615d63 100644 --- a/js/inbox_controller.js +++ b/js/inbox_controller.js @@ -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({ diff --git a/js/index.js b/js/index.js index 4b67276e4db..a5a5950bdf9 100644 --- a/js/index.js +++ b/js/index.js @@ -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(""); } }());