From d3dbf2328fcdd527ce8b97d218a4e368842f9125 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 25 Mar 2015 17:54:45 -0700 Subject: [PATCH] Set unread count badge when background page is refreshed Refreshing the background page unsets the badge. --- js/inbox_controller.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/js/inbox_controller.js b/js/inbox_controller.js index a720cd5d157..c1a8566341e 100644 --- a/js/inbox_controller.js +++ b/js/inbox_controller.js @@ -34,12 +34,7 @@ var prev = model.previous('unreadCount') || 0; if (count < prev) { // decreased var newUnreadCount = textsecure.storage.get("unreadCount", 0) - (prev - count); - if (newUnreadCount <= 0) { - newUnreadCount = 0; - extension.navigator.setBadgeText(""); - } else { - extension.navigator.setBadgeText(newUnreadCount); - } + setUnreadCount(newUnreadCount); textsecure.storage.put("unreadCount", newUnreadCount); } }); @@ -57,4 +52,13 @@ extension.on('message', fetch); fetch(); + setUnreadCount(textsecure.storage.get("unreadCount", 0)); + + function setUnreadCount(count) { + if (count > 0) { + extension.navigator.setBadgeText(count); + } else { + extension.navigator.setBadgeText(""); + } + } })();