From da237350621495b965fe22d7429d80a23e1fee7a Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 21 Sep 2015 08:28:45 +1000 Subject: [PATCH] FEATURE: Add title notification to topics --- app/assets/javascripts/discourse.js | 14 ++++++++++++++ .../javascripts/discourse/controllers/topic.js.es6 | 1 + 2 files changed, 15 insertions(+) diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index ebe4da3ee99..9c790e3fe42 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -78,6 +78,20 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, { this.set('notifyCount', count); }, + notifyBackgroundCountIncrement: function() { + if (!this.get('hasFocus')) { + this.set('backgroundNotify', true); + this.set('notifyCount', (this.get('notifyCount') || 0) + 1); + } + }, + + resetBackgroundNotifyCount: function() { + if (this.get('hasFocus') && this.get('backgroundNotify')) { + this.set('notifyCount', 0); + } + this.set('backgroundNotify', false); + }.observes('hasFocus'), + authenticationComplete: function(options) { // TODO, how to dispatch this to the controller without the container? var loginController = Discourse.__container__.lookup('controller:login'); diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index 725ec0ce73c..fd7b3977940 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -594,6 +594,7 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { } case "created": { postStream.triggerNewPostInStream(data.id); + Discourse.notifyBackgroundCountIncrement(); return; } default: {