From a6670c6c83b808313f496e0144cf79c8c6ef310b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 16 May 2014 14:04:34 -0400 Subject: [PATCH] Convert all initializers to Ember initializers --- app/assets/javascripts/discourse.js | 1 + .../initializers/1_click_interceptor.js | 32 -------- .../initializers/1_init_message_bus.js | 36 --------- .../initializers/click-interceptor.js.es6 | 32 ++++++++ .../discourse/initializers/focus-event.js.es6 | 18 +++++ .../discourse/initializers/focus_event.js | 16 ---- .../discourse/initializers/init_mobile.js | 7 -- .../initializers/keyboard-shortcuts.js.es6 | 11 +++ .../initializers/keyboard_shortcuts.js | 8 -- .../initializers/live-development.js.es6 | 75 +++++++++++++++++++ .../initializers/live_development.js | 73 ------------------ .../discourse/initializers/message-bus.js.es6 | 39 ++++++++++ .../discourse/initializers/mobile.js.es6 | 11 +++ .../initializers/page-tracking.js.es6 | 27 +++++++ .../discourse/initializers/page_tracking.js | 22 ------ .../initializers/relative-ages.js.es6 | 11 +++ .../discourse/initializers/relative_ages.js | 12 --- .../initializers/sniff-capabilities.js.es6 | 28 +++++++ .../initializers/sniff_capabilities.js | 26 ------- .../subscribe-user-notifications.js.es6 | 33 ++++++++ .../subscribe_user_notifications.js | 33 -------- 21 files changed, 286 insertions(+), 265 deletions(-) delete mode 100644 app/assets/javascripts/discourse/initializers/1_click_interceptor.js delete mode 100644 app/assets/javascripts/discourse/initializers/1_init_message_bus.js create mode 100644 app/assets/javascripts/discourse/initializers/click-interceptor.js.es6 create mode 100644 app/assets/javascripts/discourse/initializers/focus-event.js.es6 delete mode 100644 app/assets/javascripts/discourse/initializers/focus_event.js delete mode 100644 app/assets/javascripts/discourse/initializers/init_mobile.js create mode 100644 app/assets/javascripts/discourse/initializers/keyboard-shortcuts.js.es6 delete mode 100644 app/assets/javascripts/discourse/initializers/keyboard_shortcuts.js create mode 100644 app/assets/javascripts/discourse/initializers/live-development.js.es6 delete mode 100644 app/assets/javascripts/discourse/initializers/live_development.js create mode 100644 app/assets/javascripts/discourse/initializers/message-bus.js.es6 create mode 100644 app/assets/javascripts/discourse/initializers/mobile.js.es6 create mode 100644 app/assets/javascripts/discourse/initializers/page-tracking.js.es6 delete mode 100644 app/assets/javascripts/discourse/initializers/page_tracking.js create mode 100644 app/assets/javascripts/discourse/initializers/relative-ages.js.es6 delete mode 100644 app/assets/javascripts/discourse/initializers/relative_ages.js create mode 100644 app/assets/javascripts/discourse/initializers/sniff-capabilities.js.es6 delete mode 100644 app/assets/javascripts/discourse/initializers/sniff_capabilities.js create mode 100644 app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 delete mode 100644 app/assets/javascripts/discourse/initializers/subscribe_user_notifications.js diff --git a/app/assets/javascripts/discourse.js b/app/assets/javascripts/discourse.js index a00e1e37fd0..eddd1b1e9c8 100644 --- a/app/assets/javascripts/discourse.js +++ b/app/assets/javascripts/discourse.js @@ -104,6 +104,7 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, { Default is false, for next run loop. If unsure, use false. **/ addInitializer: function(init, immediate) { + Em.warn("`Discouse.addInitializer` is deprecated. Export an Ember initializer instead."); Discourse.initializers = Discourse.initializers || []; Discourse.initializers.push({fn: init, immediate: !!immediate}); }, diff --git a/app/assets/javascripts/discourse/initializers/1_click_interceptor.js b/app/assets/javascripts/discourse/initializers/1_click_interceptor.js deleted file mode 100644 index 71b5a178082..00000000000 --- a/app/assets/javascripts/discourse/initializers/1_click_interceptor.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - Discourse does some server side rendering of HTML, such as the `cooked` contents of - posts. The downside of this in an Ember app is the links will not go through the router. - This jQuery code intercepts clicks on those links and routes them properly. -**/ - -Discourse.addInitializer(function() { - - $('#main').on('click.discourse', 'a', function(e) { - if (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey) { return; } - - var $currentTarget = $(e.currentTarget), - href = $currentTarget.attr('href'); - - if (!href || - href === '#' || - $currentTarget.attr('target') || - $currentTarget.data('ember-action') || - $currentTarget.data('auto-route') || - $currentTarget.hasClass('ember-view') || - $currentTarget.hasClass('lightbox') || - href.indexOf("mailto:") === 0 || - (href.match(/^http[s]?:\/\//i) && !href.match(new RegExp("^http:\\/\\/" + window.location.hostname, "i")))) { - return; - } - - e.preventDefault(); - Discourse.URL.routeTo(href); - return false; - }); - -}, true); \ No newline at end of file diff --git a/app/assets/javascripts/discourse/initializers/1_init_message_bus.js b/app/assets/javascripts/discourse/initializers/1_init_message_bus.js deleted file mode 100644 index b5c3cc6bc5f..00000000000 --- a/app/assets/javascripts/discourse/initializers/1_init_message_bus.js +++ /dev/null @@ -1,36 +0,0 @@ -/** - Initialize the message bus to receive messages. -**/ -Discourse.addInitializer(function() { - - // We don't use the message bus in testing - if (Discourse.testing) { return; } - - Discourse.MessageBus.alwaysLongPoll = Discourse.Environment === "development"; - Discourse.MessageBus.start(); - - Discourse.MessageBus.subscribe("/global/asset-version", function(version){ - Discourse.set("assetVersion", version); - - if(Discourse.get("requiresRefresh")) { - // since we can do this transparently for people browsing the forum - // hold back the message a couple of hours - setTimeout(function() { - bootbox.confirm(I18n.lookup("assets_changed_confirm"), function(result){ - if (result) { - document.location.reload(); - } - }); - }, 1000 * 60 * 120); - } - - }); - - // initialize read-only mode and subscribe to updates via the message bus - Discourse.set("isReadOnly", Discourse.Site.currentProp("is_readonly")); - Discourse.MessageBus.subscribe("/site/read-only", function (enabled) { - Discourse.set("isReadOnly", enabled); - }); - - Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus); -}, true); diff --git a/app/assets/javascripts/discourse/initializers/click-interceptor.js.es6 b/app/assets/javascripts/discourse/initializers/click-interceptor.js.es6 new file mode 100644 index 00000000000..7a766bea77b --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/click-interceptor.js.es6 @@ -0,0 +1,32 @@ +/** + Discourse does some server side rendering of HTML, such as the `cooked` contents of + posts. The downside of this in an Ember app is the links will not go through the router. + This jQuery code intercepts clicks on those links and routes them properly. +**/ +export default { + name: "click-interceptor", + initialize: function() { + $('#main').on('click.discourse', 'a', function(e) { + if (e.isDefaultPrevented() || e.shiftKey || e.metaKey || e.ctrlKey) { return; } + + var $currentTarget = $(e.currentTarget), + href = $currentTarget.attr('href'); + + if (!href || + href === '#' || + $currentTarget.attr('target') || + $currentTarget.data('ember-action') || + $currentTarget.data('auto-route') || + $currentTarget.hasClass('ember-view') || + $currentTarget.hasClass('lightbox') || + href.indexOf("mailto:") === 0 || + (href.match(/^http[s]?:\/\//i) && !href.match(new RegExp("^http:\\/\\/" + window.location.hostname, "i")))) { + return; + } + + e.preventDefault(); + Discourse.URL.routeTo(href); + return false; + }); + } +}; diff --git a/app/assets/javascripts/discourse/initializers/focus-event.js.es6 b/app/assets/javascripts/discourse/initializers/focus-event.js.es6 new file mode 100644 index 00000000000..bf137e3004c --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/focus-event.js.es6 @@ -0,0 +1,18 @@ +/** + Keep track of when the browser is in focus. +**/ +export default { + name: 'focus-event', + + initialize: function() { + + // Default to true + Discourse.set('hasFocus', true); + + $(window).focus(function() { + Discourse.setProperties({hasFocus: true, notify: false}); + }).blur(function() { + Discourse.set('hasFocus', false); + }); + } +}; diff --git a/app/assets/javascripts/discourse/initializers/focus_event.js b/app/assets/javascripts/discourse/initializers/focus_event.js deleted file mode 100644 index 6c50db77fd4..00000000000 --- a/app/assets/javascripts/discourse/initializers/focus_event.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - Keep track of when the browser is in focus. -**/ -Discourse.addInitializer(function() { - - // Default to true - this.set('hasFocus', true); - - var self = this; - $(window).focus(function() { - self.setProperties({hasFocus: true, notify: false}); - }).blur(function() { - self.set('hasFocus', false); - }); - -}, true); \ No newline at end of file diff --git a/app/assets/javascripts/discourse/initializers/init_mobile.js b/app/assets/javascripts/discourse/initializers/init_mobile.js deleted file mode 100644 index 57e8b32e8bb..00000000000 --- a/app/assets/javascripts/discourse/initializers/init_mobile.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - Initializes the `Discourse.Mobile` helper object. -**/ -Discourse.addInitializer(function() { - Discourse.Mobile.init(); -}, true); - diff --git a/app/assets/javascripts/discourse/initializers/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/initializers/keyboard-shortcuts.js.es6 new file mode 100644 index 00000000000..7cc8e63d295 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/keyboard-shortcuts.js.es6 @@ -0,0 +1,11 @@ +/*global Mousetrap:true*/ + +/** + Initialize Global Keyboard Shortcuts +**/ +export default { + name: "keyboard-shortcuts", + initialize: function() { + Discourse.KeyboardShortcuts.bindEvents(Mousetrap); + } +}; diff --git a/app/assets/javascripts/discourse/initializers/keyboard_shortcuts.js b/app/assets/javascripts/discourse/initializers/keyboard_shortcuts.js deleted file mode 100644 index 54061824d4b..00000000000 --- a/app/assets/javascripts/discourse/initializers/keyboard_shortcuts.js +++ /dev/null @@ -1,8 +0,0 @@ -/*global Mousetrap:true*/ - -/** - Initialize Global Keyboard Shortcuts -**/ -Discourse.addInitializer(function() { - Discourse.KeyboardShortcuts.bindEvents(Mousetrap); -}); diff --git a/app/assets/javascripts/discourse/initializers/live-development.js.es6 b/app/assets/javascripts/discourse/initializers/live-development.js.es6 new file mode 100644 index 00000000000..74c903f809a --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/live-development.js.es6 @@ -0,0 +1,75 @@ +/** + Use the message bus for live reloading of components for faster development. +**/ +export default { + name: "live-development", + initialize: function() { + + // subscribe to any site customizations that are loaded + $('link.custom-css').each(function() { + var split = this.href.split("/"), + id = split[split.length - 1].split(".css")[0], + self = this; + + return Discourse.MessageBus.subscribe("/file-change/" + id, function(data) { + if (!$(self).data('orig')) { + $(self).data('orig', self.href); + } + var orig = $(self).data('orig'), + sp = orig.split(".css?"); + + self.href = sp[0] + ".css?" + data; + }); + }); + + // Custom header changes + $('header.custom').each(function() { + var header = $(this); + return Discourse.MessageBus.subscribe("/header-change/" + $(this).data('key'), function(data) { + return header.html(data); + }); + }); + + // Observe file changes + Discourse.MessageBus.subscribe("/file-change", function(data) { + Ember.TEMPLATES.empty = Handlebars.compile("
"); + _.each(data,function(me) { + + if (me === "refresh") { + // Refresh if necessary + document.location.reload(true); + } else if (me.name.substr(-10) === "handlebars") { + + // Reload handlebars + var js = me.name.replace(".handlebars", "").replace("app/assets/javascripts", "/assets"); + $LAB.script(js + "?hash=" + me.hash).wait(function() { + var templateName; + templateName = js.replace(".js", "").replace("/assets/", ""); + return _.each(Ember.View.views, function(view) { + if (view.get('templateName') === templateName) { + view.set('templateName', 'empty'); + view.rerender(); + Em.run.schedule('afterRender', function() { + view.set('templateName', templateName); + view.rerender(); + }); + } + }); + }); + + } else { + $('link').each(function() { + // TODO: stop bundling css in DEV please + if (true || (this.href.match(me.name) && me.hash)) { + if (!$(this).data('orig')) { + $(this).data('orig', this.href); + } + var orig = $(this).data('orig'); + this.href = orig + (orig.indexOf('?') >= 0 ? "&hash=" : "?hash=") + me.hash; + } + }); + } + }); + }); + } +}; diff --git a/app/assets/javascripts/discourse/initializers/live_development.js b/app/assets/javascripts/discourse/initializers/live_development.js deleted file mode 100644 index 69a6b4eddc9..00000000000 --- a/app/assets/javascripts/discourse/initializers/live_development.js +++ /dev/null @@ -1,73 +0,0 @@ -/** - Use the message bus for live reloading of components for faster development. -**/ -Discourse.addInitializer(function() { - - // subscribe to any site customizations that are loaded - $('link.custom-css').each(function() { - var split = this.href.split("/"), - id = split[split.length - 1].split(".css")[0], - self = this; - - return Discourse.MessageBus.subscribe("/file-change/" + id, function(data) { - if (!$(self).data('orig')) { - $(self).data('orig', self.href); - } - var orig = $(self).data('orig'), - sp = orig.split(".css?"); - - self.href = sp[0] + ".css?" + data; - }); - }); - - // Custom header changes - $('header.custom').each(function() { - var header = $(this); - return Discourse.MessageBus.subscribe("/header-change/" + $(this).data('key'), function(data) { - return header.html(data); - }); - }); - - // Observe file changes - return Discourse.MessageBus.subscribe("/file-change", function(data) { - Ember.TEMPLATES.empty = Handlebars.compile("
"); - _.each(data,function(me) { - - if (me === "refresh") { - // Refresh if necessary - document.location.reload(true); - } else if (me.name.substr(-10) === "handlebars") { - - // Reload handlebars - var js = me.name.replace(".handlebars", "").replace("app/assets/javascripts", "/assets"); - $LAB.script(js + "?hash=" + me.hash).wait(function() { - var templateName; - templateName = js.replace(".js", "").replace("/assets/", ""); - return _.each(Ember.View.views, function(view) { - if (view.get('templateName') === templateName) { - view.set('templateName', 'empty'); - view.rerender(); - Em.run.schedule('afterRender', function() { - view.set('templateName', templateName); - view.rerender(); - }); - } - }); - }); - - } else { - $('link').each(function() { - // TODO: stop bundling css in DEV please - if (true || (this.href.match(me.name) && me.hash)) { - if (!$(this).data('orig')) { - $(this).data('orig', this.href); - } - var orig = $(this).data('orig'); - this.href = orig + (orig.indexOf('?') >= 0 ? "&hash=" : "?hash=") + me.hash; - } - }); - } - }); - }); - -}, true); diff --git a/app/assets/javascripts/discourse/initializers/message-bus.js.es6 b/app/assets/javascripts/discourse/initializers/message-bus.js.es6 new file mode 100644 index 00000000000..b863ca899f7 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/message-bus.js.es6 @@ -0,0 +1,39 @@ +/** + Initialize the message bus to receive messages. +**/ +export default { + name: "message-bus", + initialize: function() { + + // We don't use the message bus in testing + if (Discourse.testing) { return; } + + Discourse.MessageBus.alwaysLongPoll = Discourse.Environment === "development"; + Discourse.MessageBus.start(); + + Discourse.MessageBus.subscribe("/global/asset-version", function(version){ + Discourse.set("assetVersion", version); + + if(Discourse.get("requiresRefresh")) { + // since we can do this transparently for people browsing the forum + // hold back the message a couple of hours + setTimeout(function() { + bootbox.confirm(I18n.lookup("assets_changed_confirm"), function(result){ + if (result) { + document.location.reload(); + } + }); + }, 1000 * 60 * 120); + } + + }); + + // initialize read-only mode and subscribe to updates via the message bus + Discourse.set("isReadOnly", Discourse.Site.currentProp("is_readonly")); + Discourse.MessageBus.subscribe("/site/read-only", function (enabled) { + Discourse.set("isReadOnly", enabled); + }); + + Discourse.KeyValueStore.init("discourse_", Discourse.MessageBus); + } +}; diff --git a/app/assets/javascripts/discourse/initializers/mobile.js.es6 b/app/assets/javascripts/discourse/initializers/mobile.js.es6 new file mode 100644 index 00000000000..83b3e0c86e8 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/mobile.js.es6 @@ -0,0 +1,11 @@ +/** + Initializes the `Discourse.Mobile` helper object. +**/ +export default { + name: 'mobile', + + initialize: function() { + Discourse.Mobile.init(); + } +}; + diff --git a/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 b/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 new file mode 100644 index 00000000000..7e9dad792c4 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 @@ -0,0 +1,27 @@ +/** + Sets up the PageTracking hook. +**/ +export default { + name: "page-tracking", + after: 'register-discourse-location', + + initialize: function() { + var pageTracker = Discourse.PageTracker.current(); + pageTracker.start(); + + // Out of the box, Discourse tries to track google analytics + // if it is present + if (typeof window._gaq !== 'undefined') { + pageTracker.on('change', function() { + window._gaq.push(['_trackPageview']); + }); + } + + // Also use Universal Analytics if it is present + if (typeof window.ga !== 'undefined') { + pageTracker.on('change', function() { + window.ga('send', 'pageview'); + }); + } + } +}; diff --git a/app/assets/javascripts/discourse/initializers/page_tracking.js b/app/assets/javascripts/discourse/initializers/page_tracking.js deleted file mode 100644 index aa361ccada4..00000000000 --- a/app/assets/javascripts/discourse/initializers/page_tracking.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - Sets up the PageTracking hook. -**/ -Discourse.addInitializer(function() { - var pageTracker = Discourse.PageTracker.current(); - pageTracker.start(); - - // Out of the box, Discourse tries to track google analytics - // if it is present - if (typeof window._gaq !== 'undefined') { - pageTracker.on('change', function() { - window._gaq.push(['_trackPageview']); - }); - } - - // Also use Universal Analytics if it is present - if (typeof window.ga !== 'undefined') { - pageTracker.on('change', function() { - window.ga('send', 'pageview'); - }); - } -}); diff --git a/app/assets/javascripts/discourse/initializers/relative-ages.js.es6 b/app/assets/javascripts/discourse/initializers/relative-ages.js.es6 new file mode 100644 index 00000000000..263f8d19810 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/relative-ages.js.es6 @@ -0,0 +1,11 @@ +/** + Updates the relative ages of dates on the screen. +**/ +export default { + name: "relative-ages", + initialize: function() { + setInterval(function(){ + Discourse.Formatter.updateRelativeAge($('.relative-date')); + }, 60 * 1000); + } +}; diff --git a/app/assets/javascripts/discourse/initializers/relative_ages.js b/app/assets/javascripts/discourse/initializers/relative_ages.js deleted file mode 100644 index 5888e52ab9c..00000000000 --- a/app/assets/javascripts/discourse/initializers/relative_ages.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - Updates the relative ages of dates on the screen. - -**/ -Discourse.addInitializer(function() { - - setInterval(function(){ - Discourse.Formatter.updateRelativeAge($('.relative-date')); - }, 60 * 1000); - -}, true); - diff --git a/app/assets/javascripts/discourse/initializers/sniff-capabilities.js.es6 b/app/assets/javascripts/discourse/initializers/sniff-capabilities.js.es6 new file mode 100644 index 00000000000..a624be6ec42 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/sniff-capabilities.js.es6 @@ -0,0 +1,28 @@ +/*global Modernizr:true*/ + +/** + Initializes the `Discourse.Capabilities` singleton by sniffing out the browser + capabilities. +**/ +export default { + name: "sniff-capabilities", + initialize: function() { + var $html = $('html'), + touch = $html.hasClass('touch') || (Modernizr.prefixed("MaxTouchPoints", navigator) > 1), + caps = Discourse.Capabilities.current(); + + // Store the touch ability in our capabilities object + caps.set('touch', touch); + $html.addClass(touch ? 'discourse-touch' : 'discourse-no-touch'); + + // Detect Android + if (navigator) { + var ua = navigator.userAgent; + caps.set('android', ua && ua.indexOf('Android') !== -1); + } + + // We consider high res a device with 1280 horizontal pixels. High DPI tablets like + // iPads should report as 1024. + caps.set('highRes', Modernizr.mq("only screen and (min-width: 1280px)")); + } +}; diff --git a/app/assets/javascripts/discourse/initializers/sniff_capabilities.js b/app/assets/javascripts/discourse/initializers/sniff_capabilities.js deleted file mode 100644 index bbe5b85715e..00000000000 --- a/app/assets/javascripts/discourse/initializers/sniff_capabilities.js +++ /dev/null @@ -1,26 +0,0 @@ -/*global Modernizr:true*/ - -/** - Initializes the `Discourse.Capabilities` singleton by sniffing out the browser - capabilities. -**/ -Discourse.addInitializer(function() { - var $html = $('html'), - touch = $html.hasClass('touch') || (Modernizr.prefixed("MaxTouchPoints", navigator) > 1), - caps = Discourse.Capabilities.current(); - - // Store the touch ability in our capabilities object - caps.set('touch', touch); - $html.addClass(touch ? 'discourse-touch' : 'discourse-no-touch'); - - // Detect Android - if (navigator) { - var ua = navigator.userAgent; - caps.set('android', ua && ua.indexOf('Android') !== -1); - } - - // We consider high res a device with 1280 horizontal pixels. High DPI tablets like - // iPads should report as 1024. - caps.set('highRes', Modernizr.mq("only screen and (min-width: 1280px)")); - -}, true); diff --git a/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 b/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 new file mode 100644 index 00000000000..8922f42c513 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 @@ -0,0 +1,33 @@ +/** + Subscribes to user events on the message bus +**/ +export default { + name: "subscribe-user-notifications", + after: 'message-bus', + initialize: function() { + var user = Discourse.User.current(); + if (user) { + var bus = Discourse.MessageBus; + bus.callbackInterval = Discourse.SiteSettings.polling_interval; + bus.enableLongPolling = true; + bus.baseUrl = Discourse.getURL("/"); + + if (user.admin || user.moderator) { + bus.subscribe("/flagged_counts", function(data) { + user.set('site_flagged_posts_count', data.total); + }); + } + bus.subscribe("/notification/" + user.get('id'), (function(data) { + user.set('unread_notifications', data.unread_notifications); + user.set('unread_private_messages', data.unread_private_messages); + }), user.notification_channel_position); + + bus.subscribe("/categories", function(data){ + var site = Discourse.Site.current(); + _.each(data.categories,function(c){ + site.updateCategory(c); + }); + }); + } + } +}; diff --git a/app/assets/javascripts/discourse/initializers/subscribe_user_notifications.js b/app/assets/javascripts/discourse/initializers/subscribe_user_notifications.js deleted file mode 100644 index 394377621af..00000000000 --- a/app/assets/javascripts/discourse/initializers/subscribe_user_notifications.js +++ /dev/null @@ -1,33 +0,0 @@ -/** - Updates the relative ages of dates on the screen. - -**/ -Discourse.addInitializer(function() { - - var user = Discourse.User.current(); - if (user) { - var bus = Discourse.MessageBus; - bus.callbackInterval = Discourse.SiteSettings.polling_interval; - bus.enableLongPolling = true; - bus.baseUrl = Discourse.getURL("/"); - - if (user.admin || user.moderator) { - bus.subscribe("/flagged_counts", function(data) { - user.set('site_flagged_posts_count', data.total); - }); - } - bus.subscribe("/notification/" + user.get('id'), (function(data) { - user.set('unread_notifications', data.unread_notifications); - user.set('unread_private_messages', data.unread_private_messages); - }), user.notification_channel_position); - - bus.subscribe("/categories", function(data){ - var site = Discourse.Site.current(); - _.each(data.categories,function(c){ - site.updateCategory(c); - }); - }); - } - -}, true); -