diff --git a/app/assets/javascripts/discourse/components/desktop-notification-config.js.es6 b/app/assets/javascripts/discourse/components/desktop-notification-config.js.es6 index dc4673c1714..d1ad4f28abb 100644 --- a/app/assets/javascripts/discourse/components/desktop-notification-config.js.es6 +++ b/app/assets/javascripts/discourse/components/desktop-notification-config.js.es6 @@ -1,7 +1,8 @@ import computed from 'ember-addons/ember-computed-decorators'; import KeyValueStore from 'discourse/lib/key-value-store'; +import { context } from 'discourse/lib/desktop-notifications'; -const keyValueStore = new KeyValueStore("discourse_desktop_notifications_"); +const keyValueStore = new KeyValueStore(context); export default Ember.Component.extend({ classNames: ['controls'], 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 406b050d3b8..1d8260f4015 100644 --- a/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 +++ b/app/assets/javascripts/discourse/initializers/subscribe-user-notifications.js.es6 @@ -1,5 +1,9 @@ // Subscribes to user events on the message bus -import { init as initDesktopNotifications, onNotification } from 'discourse/lib/desktop-notifications'; +import { + init as initDesktopNotifications, + onNotification, + alertChannel +} from 'discourse/lib/desktop-notifications'; export default { name: 'subscribe-user-notifications', @@ -98,10 +102,7 @@ export default { if (!Ember.testing) { if (!site.mobileView) { - bus.subscribe("/notification-alert/" + user.get('id'), function(data){ - onNotification(data, user); - }); - + bus.subscribe(alertChannel(user), data => onNotification(data, user)); initDesktopNotifications(bus); } } diff --git a/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6 b/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6 index de1d6afc338..8d5c010def4 100644 --- a/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6 +++ b/app/assets/javascripts/discourse/lib/desktop-notifications.js.es6 @@ -159,6 +159,12 @@ function i18nKey(notification_type) { return "notifications.popup." + Discourse.Site.current().get("notificationLookup")[notification_type]; } -// Exported for controllers/notification.js.es6 +function alertChannel(user) { + return `/notification-alert/${user.get('id')}`; +} -export { init, onNotification }; +function unsubscribe(bus, user) { + bus.unsubscribe(alertChannel(user)); +} + +export { context, init, onNotification, unsubscribe, alertChannel }; diff --git a/app/controllers/metadata_controller.rb b/app/controllers/metadata_controller.rb index a240bc10d1c..ab317885a19 100644 --- a/app/controllers/metadata_controller.rb +++ b/app/controllers/metadata_controller.rb @@ -3,7 +3,17 @@ class MetadataController < ApplicationController skip_before_filter :preload_json, :check_xhr, :redirect_to_login_if_required def manifest - manifest = { + render json: default_manifest.to_json + end + + def opensearch + render file: "#{Rails.root}/app/views/metadata/opensearch.xml" + end + + private + + def default_manifest + { name: SiteSetting.title, short_name: SiteSetting.title, display: 'standalone', @@ -19,11 +29,5 @@ class MetadataController < ApplicationController } ] } - - render json: manifest.to_json - end - - def opensearch - render file: "#{Rails.root}/app/views/metadata/opensearch.xml" end end diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index 5ad5d3990d8..8ba84ed3367 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -341,7 +341,7 @@ class PostAlerter # we may have an invalid post somehow, dont blow up post_url = original_post.url rescue nil if post_url - MessageBus.publish("/notification-alert/#{user.id}", { + payload = { notification_type: type, post_number: original_post.post_number, topic_title: original_post.topic.title, @@ -349,7 +349,10 @@ class PostAlerter excerpt: original_post.excerpt(400, text_entities: true, strip_links: true), username: original_username, post_url: post_url - }, user_ids: [user.id]) + } + + MessageBus.publish("/notification-alert/#{user.id}", payload, user_ids: [user.id]) + DiscourseEvent.trigger(:post_notification_alert, user, payload) end end