From 6ded33ae48fcf69be6729f7de0df167d27998ee8 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 12 Jan 2014 04:42:05 -1000 Subject: [PATCH] Badge UI --- background.js | 3 +++ helpers.js | 6 ++++++ popup.js | 15 ++++++++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/background.js b/background.js index 0ab7c473f6..f94a30a6a5 100644 --- a/background.js +++ b/background.js @@ -5,6 +5,9 @@ if (localStorage.getItem('first_install_ran')) { if (isRegistrationDone()) { subscribeToPush(function(message) { console.log("Got message from " + message.source + ": \"" + getString(message.message)); + var newUnreadCount = storage.getUnencrypted("unreadCount") + 1; + storage.putUnencrypted("unreadCount", newUnreadCount); + chrome.browserAction.setBadgeText({text: newUnreadCount + ""}); storeMessage(message); }); } diff --git a/helpers.js b/helpers.js index 7851f7b3a7..56b83963cf 100644 --- a/helpers.js +++ b/helpers.js @@ -82,6 +82,12 @@ function getDeviceId(encodedNumber) { return 1; } +function timestampToHumanReadable(timestamp) { + var date = new Date(); + date.setTime(timestamp*1000); + return date.toUTCString(); +} + /************************************************ *** Utilities to store data in local storage *** ************************************************/ diff --git a/popup.js b/popup.js index 00582ac1fd..38894c9157 100644 --- a/popup.js +++ b/popup.js @@ -30,16 +30,21 @@ if (storage.getUnencrypted("number_id") === undefined) { for (var i = 0; i < MAX_CONVERSATIONS && i < conversations.length; i++) { var conversation = conversations[i]; ul.append('
  • '); - for (var j = 0; j < MAX_MESSAGES_PER_CONVERSATION && conversation.length; j++) { - ul.append(JSON.stringify(conversation[j])); + for (var j = 0; j < MAX_MESSAGES_PER_CONVERSATION && j < conversation.length; j++) { + var message = conversation[j]; + ul.append("From: " + message.sender + ", at: " + timestampToHumanReadable(message.timestamp) + "
    "); + ul.append("Message: " + message.message + "

    "); } ul.append('
  • '); } } - $(window).bind('storage', function() { - console.log("Got localStorage update"); - fillMessages(); + $(window).bind('storage', function(e) { + console.log("Got localStorage update for key " + e.key); + if (event.key == "emessageMap")//TODO: Fix when we get actual encryption + fillMessages(); }); fillMessages(); + storage.putUnencrypted("unreadCount", 0); + chrome.browserAction.setBadgeText({text: ""}); }