Merge pull request #4298 from tgxworld/make_desktop_notifications_extendable

Refactor desktop notifications to be more modular.
This commit is contained in:
Guo Xiang Tan 2016-07-01 00:35:34 +08:00 committed by GitHub
commit aa4dccd0a1
5 changed files with 32 additions and 17 deletions

View File

@ -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'],

View File

@ -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);
}
}

View File

@ -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 };

View File

@ -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

View File

@ -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