Update webapp for /status changes
authorChip Black <bytex64@bytex64.net>
Tue, 1 Jul 2014 05:32:30 +0000 (00:32 -0500)
committerChip Black <bytex64@bytex64.net>
Tue, 1 Jul 2014 05:38:55 +0000 (00:38 -0500)
www/jssrc/blerg/API.js
www/jssrc/blerg/Blerg.js
www/jssrc/blerg/Controls.js
www/jssrc/blerg/Feed.js
www/jssrc/blerg/Tag.js

index cd85745..ecf7cd3 100644 (file)
@@ -181,19 +181,40 @@ enyo.kind({
         });
         req.go();
     },
-    getFeedInfo: function() {
+    getStatus: function() {
         if (!blerg.API.loggedIn)
             throw new Error('Cannot request feed status when not logged in');
 
         var req = new enyo.Ajax({
-            url: baseURL + '/feedinfo',
+            url: baseURL + '/status',
             method: 'POST',
             postBody: {
                 username: blerg.API.username
             }
         });
         req.response(this, function(inSender, inResponse) {
-            this.bubble('onFeedInfo', inResponse);
+            this.bubble('onStatus', inResponse);
+        });
+        req.go();
+    },
+    clearStatus: function(type) {
+        if (!blerg.API.loggedIn)
+            throw new Error('Cannot request feed status when not logged in');
+
+        if (!(type == 'feed' || type == 'mentioned'))
+            throw new Error('Invalid status clear type: ' + type);
+
+        var req = new enyo.Ajax({
+            url: baseURL + '/status',
+            method: 'POST',
+            postBody: {
+                username: blerg.API.username,
+                clear: type
+            }
+        });
+        req.response(this, function(inSender, inResponse) {
+            inResponse.type = type;
+            this.bubble('onClearStatus', inResponse);
         });
         req.go();
     },
@@ -218,7 +239,7 @@ enyo.kind({
     },
     getSubscriptionStatus: function(username) {
         var req = new enyo.Ajax({
-            url: baseURL + '/feedinfo/' + username,
+            url: baseURL + '/status/' + username,
             method: 'POST',
             postBody: {
                 username: blerg.API.username
index 352962d..361b0c9 100644 (file)
@@ -13,8 +13,7 @@ enyo.kind({
         onSetTitle: "setTitle",
         onPostVisibility: "postVisibilityUpdate",
         onReload: "sendReload",
-        onShowChangePassword: "showChangePassword",
-        onClearFeedStatus: "clearFeedStatus"
+        onShowChangePassword: "showChangePassword"
     },
     components: [
         {classes: "blerg-header", components: [
@@ -100,8 +99,5 @@ enyo.kind({
     },
     showChangePassword: function() {
         this.$.passwdDialog.show();
-    },
-    clearFeedStatus: function() {
-        this.$.controls.waterfall('onClearFeedStatus');
     }
 });
index 0827ff7..eb3275c 100644 (file)
@@ -10,8 +10,7 @@ enyo.kind({
     handlers: {
         onLogin: "login",
         onLogout: "logout",
-        onPostVisibility: "postVisibilityUpdate",
-        onClearFeedStatus: "clearFeedStatus"
+        onPostVisibility: "postVisibilityUpdate"
     },
     components: [
         {name: "loggedOutControls", components: [
@@ -39,13 +38,15 @@ enyo.kind({
                 {tag: null, content: "."}
             ]},
             {classes: "blerg-controls-toolbar", components: [
-                {kind: "onyx.Button", content: "Feed Your Vanity", onclick: "chatterClicked"},
+                {name: "mentionButton", kind: "onyx.Button", content: "Feed Your Vanity", onclick: "chatterClicked"},
                 {name: "feedButton", kind: "onyx.Button", classes: "feed-button", content: "Stalk Your Victims", onclick: "feedClicked"},
                 {name: "spewButton", kind: "onyx.Button", classes: "spew-button", content: "Spew It!", onclick: "spewToggle"}
             ]},
         ]},
         {name: "api", kind: "blerg.API",
-         onFeedInfo: "gotFeedInfo"}
+         onStatus: "gotStatus"},
+        {kind: "Signals", 
+         onClearNotification: "clearNotification"}
     ],
     showRSS: function(url) {
         this.$.rssButton.show();
@@ -95,9 +96,9 @@ enyo.kind({
         this.$.userlink.setContent('@' + inEvent.username);
         this.username = inEvent.username;
 
-        this.updateFeedInfo();
+        this.updateStatus();
         this.feedStatusUpdateInterval = setInterval(function() {
-            this.updateFeedInfo();
+            this.updateStatus();
         }.bind(this), 900000);
     },
     logout: function(inSender, inEvent) {
@@ -115,15 +116,20 @@ enyo.kind({
         this.postShowing = inEvent.showing;
         this.$.spewButton.addRemoveClass('active', inEvent.showing);
     },
-    updateFeedInfo: function() {
-        this.$.api.getFeedInfo();
+    updateStatus: function() {
+        this.$.api.getStatus();
     },
-    gotFeedInfo: function(inSender, inEvent) {
-        this.$.feedButton.addRemoveClass('new', inEvent.new > 0);
-        if (inEvent.new > 0) {
-            this.$.feedButton.setContent('Stalk Your Victims (' + inEvent.new + ')');
-        } else {
-            this.$.feedButton.setContent('Stalk Your Victims');
+    gotStatus: function(inSender, inEvent) {
+        if ('mentioned' in inEvent) {
+            this.$.mentionButton.addRemoveClass('new', inEvent.mentioned);
+        }
+        if ('feed_new' in inEvent) {
+            this.$.feedButton.addRemoveClass('new', inEvent.feed_new > 0);
+            if (inEvent.feed_new > 0) {
+                this.$.feedButton.setContent('Stalk Your Victims (' + inEvent.feed_new + ')');
+            } else {
+                this.$.feedButton.setContent('Stalk Your Victims');
+            }
         }
     },
     chatterClicked: function() {
@@ -134,7 +140,11 @@ enyo.kind({
         window.location.href = '/#/feed';
         this.bubble('onNavigate');
     },
-    clearFeedStatus: function() {
-        this.gotFeedInfo(this, {new: 0});
+    clearNotification: function(inSender, inEvent) {
+        if (inEvent.type == 'feed') {
+            this.gotStatus(this, {feed_new: 0});
+        } else if (inEvent.type == 'mentioned') {
+            this.gotStatus(this, {mentioned: false});
+        }
     }
 });
index 98e7ffb..05a549a 100644 (file)
@@ -15,7 +15,8 @@ enyo.kind({
         {name: "records"},
         {name: "spinner", kind: "OldSchoolSpinner", showing: false},
         {name: "api", kind: "blerg.API",
-         onItemsLoaded: "itemsLoaded"}
+         onItemsLoaded: "itemsLoaded",
+         onClearStatus: "clearStatus"}
     ],
     statics: {
         locationDetect: function(l) {
@@ -35,6 +36,11 @@ enyo.kind({
     },
     itemsLoaded: function(inSender, inEvent) {
         this.addItems(inEvent.entries);
-        this.bubble('onClearFeedStatus');
+        this.$.api.clearStatus('feed');
+    },
+    clearStatus: function(inSender, inEvent) {
+        if (inEvent.type == 'feed' && inEvent.status == 'success') {
+            enyo.Signals.send('onClearNotification', {type: inEvent.type});
+        }
     }
 });
index 934c183..0d77dab 100644 (file)
@@ -17,7 +17,8 @@ enyo.kind({
         {name: "records"},
         {name: "spinner", kind: "OldSchoolSpinner", showing: false},
         {name: "api", kind: "blerg.API",
-         onItemsLoaded: "itemsLoaded"}
+         onItemsLoaded: "itemsLoaded",
+         onClearStatus: "clearStatus"}
     ],
     statics: {
         locationDetect: function(l) {
@@ -55,5 +56,13 @@ enyo.kind({
     },
     itemsLoaded: function(inSender, inEvent) {
         this.addItems(inEvent.entries);
+        if (this.type == 'ref' && blerg.API.loggedIn && blerg.API.username == this.tag) {
+            this.$.api.clearStatus('mentioned');
+        }
+    },
+    clearStatus: function(inSender, inEvent) {
+        if (inEvent.type == 'mentioned' && inEvent.status == 'success') {
+            enyo.Signals.send('onClearNotification', {type: inEvent.type});
+        }
     }
 });