diff --git a/js/inbox_controller.js b/js/inbox_controller.js index 77dfa22e..a19da615 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 4b67276e..a5a5950b 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(""); } }());