diff --git a/app/assets/javascripts/discourse/components/notification_item_component.js b/app/assets/javascripts/discourse/components/notification_item_component.js new file mode 100644 index 00000000000..238f79651bc --- /dev/null +++ b/app/assets/javascripts/discourse/components/notification_item_component.js @@ -0,0 +1,11 @@ +Discourse.NotificationItemComponent = Ember.Component.extend({ + tagName: 'span', + didInsertElement: function(){ + var self = this; + this.$('a').click(function(){ + self.set('model.read', true); + self.rerender(); + return true; + }); + } +}); diff --git a/app/assets/javascripts/discourse/controllers/header.js.es6 b/app/assets/javascripts/discourse/controllers/header.js.es6 index dcfe1ee6d62..ca4198d527a 100644 --- a/app/assets/javascripts/discourse/controllers/header.js.es6 +++ b/app/assets/javascripts/discourse/controllers/header.js.es6 @@ -16,6 +16,10 @@ export default Discourse.Controller.extend({ return Discourse.User.current() && !this.get('topic.isPrivateMessage'); }.property('topic.isPrivateMessage'), + resetCachedNotifications: function(){ + this.set("notifications", null); + }.observes("currentUser.lastNotificationChange"), + actions: { toggleStar: function() { var topic = this.get('topic'); @@ -29,10 +33,11 @@ export default Discourse.Controller.extend({ 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, - 'currentUser.unread_notifications': 0 + loading_notifications: false }); }); } diff --git a/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 b/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 index 8922f42c513..69deb2c28c4 100644 --- a/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 +++ b/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 @@ -18,8 +18,15 @@ export default { }); } bus.subscribe("/notification/" + user.get('id'), (function(data) { + var oldUnread = user.get('unread_notifications'); + var oldPM = user.get('unread_private_messages'); + user.set('unread_notifications', data.unread_notifications); user.set('unread_private_messages', data.unread_private_messages); + + if(oldUnread !== data.unread_notifications || oldPM !== data.unread_private_messages) { + user.set('lastNotificationChange', new Date()); + } }), user.notification_channel_position); bus.subscribe("/categories", function(data){ diff --git a/app/assets/javascripts/discourse/templates/components/notification-item.js.handlebars b/app/assets/javascripts/discourse/templates/components/notification-item.js.handlebars new file mode 100644 index 00000000000..50879cae4ff --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/notification-item.js.handlebars @@ -0,0 +1 @@ +{{unbound boundI18n scope linkBinding="model.link" usernameBinding="model.username"}} diff --git a/app/assets/javascripts/discourse/templates/notifications.js.handlebars b/app/assets/javascripts/discourse/templates/notifications.js.handlebars index f86ddcb4dcd..dd856989ea0 100644 --- a/app/assets/javascripts/discourse/templates/notifications.js.handlebars +++ b/app/assets/javascripts/discourse/templates/notifications.js.handlebars @@ -3,7 +3,7 @@ {{#if content}}