From 626be60457401042854cab447a01ed4120b78886 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Tue, 1 Jul 2014 00:32:30 -0500 Subject: [PATCH] Update webapp for /status changes --- www/jssrc/blerg/API.js | 29 +++++++++++++++++++++---- www/jssrc/blerg/Blerg.js | 6 +----- www/jssrc/blerg/Controls.js | 42 +++++++++++++++++++++++-------------- www/jssrc/blerg/Feed.js | 10 +++++++-- www/jssrc/blerg/Tag.js | 11 +++++++++- 5 files changed, 70 insertions(+), 28 deletions(-) diff --git a/www/jssrc/blerg/API.js b/www/jssrc/blerg/API.js index cd85745..ecf7cd3 100644 --- a/www/jssrc/blerg/API.js +++ b/www/jssrc/blerg/API.js @@ -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 diff --git a/www/jssrc/blerg/Blerg.js b/www/jssrc/blerg/Blerg.js index 352962d..361b0c9 100644 --- a/www/jssrc/blerg/Blerg.js +++ b/www/jssrc/blerg/Blerg.js @@ -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'); } }); diff --git a/www/jssrc/blerg/Controls.js b/www/jssrc/blerg/Controls.js index 0827ff7..eb3275c 100644 --- a/www/jssrc/blerg/Controls.js +++ b/www/jssrc/blerg/Controls.js @@ -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}); + } } }); diff --git a/www/jssrc/blerg/Feed.js b/www/jssrc/blerg/Feed.js index 98e7ffb..05a549a 100644 --- a/www/jssrc/blerg/Feed.js +++ b/www/jssrc/blerg/Feed.js @@ -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}); + } } }); diff --git a/www/jssrc/blerg/Tag.js b/www/jssrc/blerg/Tag.js index 934c183..0d77dab 100644 --- a/www/jssrc/blerg/Tag.js +++ b/www/jssrc/blerg/Tag.js @@ -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}); + } } }); -- 2.25.1