Add new message bits to web
authorChip Black <bytex64@bytex64.net>
Tue, 19 Jul 2011 02:11:05 +0000 (21:11 -0500)
committerChip Black <bytex64@bytex64.net>
Tue, 19 Jul 2011 02:11:05 +0000 (21:11 -0500)
www/index.html
www/js/blerg.js

index 4437546..c1db6e9 100644 (file)
@@ -36,7 +36,7 @@
       Hello, <a href="#" id="userlink" onclick="return qlink()"></a>. <a href="#" onclick="loginStatus.logout(); return false">logout</a><br>
       <a href="#" onclick="postPopup(); return false">Write new entry</a><br>
       <a href="#" id="reflink" onclick="return qlink()">Chatter about me</a><br>
-      <a href="#/feed" onclick="return qlink()">Stalk your victims</a>
+      <a href="#/feed" onclick="return qlink()">Stalk your victims <span id="newFeedMessages"></span></a>
     </div>
     <div id="rss" style="display:none"><a id="rsslink" href=""><img src="images/rss.png" width="16" height="16"> RSS</a></div>
   </div>
index 724405f..83a8a88 100644 (file)
@@ -31,6 +31,8 @@ function LoginStatus() {
     if (cookies.auth && cookies.username) {
         this.loggedIn = true;
         this.username = cookies.username;
+        this.requestFeedStatus();
+        this.feedStatusUpdateInterval = setInterval(this.requestFeedStatus.bind(this), 900000);
     } else {
         this.loggedIn = false;
         this.username = null;
@@ -51,6 +53,8 @@ LoginStatus.prototype.login = function(username, password) {
                 this.username = username;
                 document.cookie = "username=" + username;
                 $('login.password').value = '';
+                this.requestFeedStatus();
+                this.feedStatusUpdateInterval = setInterval(this.requestFeedStatus.bind(this), 900000);
                 this.update();
             } else {
                 alert("Could not log in");
@@ -73,6 +77,7 @@ LoginStatus.prototype.logout = function() {
             this.loggedIn = false;
             document.cookie = "auth=; expires=1-Jan-1970 00:00:00 GMT";
             this.update();
+            clearInterval(this.feedStatusUpdateInterval);
         }.bind(this)
     });
     document.cookie = "username=; expires=1-Jan-1970 00:00:00 GMT";
@@ -123,6 +128,19 @@ LoginStatus.prototype.post = function(msg) {
     });
 }
 
+LoginStatus.prototype.requestFeedStatus = function() {
+    new Ajax.Request('/feedinfo', {
+        parameters: { username: this.username },
+        onSuccess: function(r) {
+            var j = r.responseText.evalJSON();
+            if (j['new'] > 0) {
+                $('newFeedMessages').update('(' + j['new'] + ' new)');
+            } else {
+                $('newFeedMessages').update('');
+            }
+        }
+    });
+}
 
 // Base object for paged data
 function Pager() {
@@ -540,6 +558,7 @@ function Feed(m) {
                 if (!this.pageStart)
                     this.pageStart = response.length - 1;
                 this.itemCount = response.length;
+                loginStatus.requestFeedStatus();
             }
             this.displayItems();
         }.bind(this),