diff --git a/background.js b/background.js index 0ab7c473f..f94a30a6a 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 7851f7b3a..56b83963c 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 00582ac1f..38894c915 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: ""}); }