From 2042ed02ec52cc57dafadddaf6d05b2c35a74d6e Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Tue, 10 Jun 2014 11:44:49 +1000 Subject: [PATCH] BUGFIX: notifications cleared incorrectly The notifications panel would reset itself if you got a notification while it was open New behavior, we refresh the panel live, blue notification is cleared automatically if its open. If window is not visible it will close the notifications panel, that way you don't miss notifications by accident. --- .../discourse/controllers/header.js.es6 | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/header.js.es6 b/app/assets/javascripts/discourse/controllers/header.js.es6 index ca4198d527a..0a6af7f6e53 100644 --- a/app/assets/javascripts/discourse/controllers/header.js.es6 +++ b/app/assets/javascripts/discourse/controllers/header.js.es6 @@ -17,9 +17,40 @@ export default Discourse.Controller.extend({ }.property('topic.isPrivateMessage'), resetCachedNotifications: function(){ - this.set("notifications", null); + // a bit hacky, but if we have no focus, hide notifications first + var visible = $("#notifications-dropdown").is(":visible"); + + if(!Discourse.get("hasFocus")) { + if(visible){ + $("html").click(); + } + this.set("notifications", null); + return; + } + if(visible){ + this.refreshNotifications(); + } else { + this.set("notifications", null); + } }.observes("currentUser.lastNotificationChange"), + refreshNotifications: function(){ + var self = this; + + if(self.get("loading_notifications")){return;} + + self.set("loading_notifications", true); + Discourse.ajax("/notifications").then(function(result) { + self.set('currentUser.unread_notifications', 0); + self.setProperties({ + notifications: result, + loading_notifications: false + }); + }, function(){ + self.set("loading_notifications", false); + }); + }, + actions: { toggleStar: function() { var topic = this.get('topic'); @@ -31,15 +62,7 @@ export default Discourse.Controller.extend({ var self = this; if (self.get('currentUser.unread_notifications') || self.get('currentUser.unread_private_messages') || !self.get('notifications')) { - self.set("loading_notifications", true); - Discourse.ajax("/notifications").then(function(result) { - self.set('currentUser.unread_notifications', 0); - - self.setProperties({ - notifications: result, - loading_notifications: false - }); - }); + self.refreshNotifications(); } headerView.showDropdownBySelector("#user-notifications"); },