Refactor desktop notifications to be more modular.
This commit is contained in:
parent
5dcdfb9777
commit
904d9735ab
|
@ -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'],
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue