mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Merge pull request #3714 from riking/live-settings
FEATURE: Live-update site settings
This commit is contained in:
commit
da25abfcc9
3 changed files with 38 additions and 25 deletions
|
@ -7,7 +7,9 @@ export default {
|
|||
// We don't use the message bus in testing
|
||||
if (Discourse.testing) { return; }
|
||||
|
||||
const messageBus = container.lookup('message-bus:main');
|
||||
const messageBus = container.lookup('message-bus:main'),
|
||||
user = container.lookup('current-user:main'),
|
||||
siteSettings = container.lookup('site-settings:main');
|
||||
|
||||
const deprecatedBus = {};
|
||||
deprecatedBus.prototype = messageBus;
|
||||
|
@ -20,5 +22,25 @@ export default {
|
|||
messageBus.alwaysLongPoll = Discourse.Environment === "development";
|
||||
messageBus.start();
|
||||
Discourse.KeyValueStore.init("discourse_", messageBus);
|
||||
|
||||
messageBus.callbackInterval = siteSettings.anon_polling_interval;
|
||||
messageBus.backgroundCallbackInterval = siteSettings.background_polling_interval;
|
||||
messageBus.baseUrl = siteSettings.long_polling_base_url;
|
||||
|
||||
if (messageBus.baseUrl !== '/') {
|
||||
// zepto compatible, 1 param only
|
||||
messageBus.ajax = function(opts) {
|
||||
opts.headers = opts.headers || {};
|
||||
opts.headers['X-Shared-Session-Key'] = $('meta[name=shared_session_key]').attr('content');
|
||||
return $.ajax(opts);
|
||||
};
|
||||
} else {
|
||||
messageBus.baseUrl = Discourse.getURL('/');
|
||||
}
|
||||
|
||||
if (user) {
|
||||
messageBus.callbackInterval = siteSettings.polling_interval;
|
||||
messageBus.enableLongPolling = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10,24 +10,7 @@ export default {
|
|||
siteSettings = container.lookup('site-settings:main'),
|
||||
bus = container.lookup('message-bus:main');
|
||||
|
||||
bus.callbackInterval = siteSettings.anon_polling_interval;
|
||||
bus.backgroundCallbackInterval = siteSettings.background_polling_interval;
|
||||
bus.baseUrl = siteSettings.long_polling_base_url;
|
||||
|
||||
if (bus.baseUrl !== '/') {
|
||||
// zepto compatible, 1 param only
|
||||
bus.ajax = function(opts) {
|
||||
opts.headers = opts.headers || {};
|
||||
opts.headers['X-Shared-Session-Key'] = $('meta[name=shared_session_key]').attr('content');
|
||||
return $.ajax(opts);
|
||||
};
|
||||
} else {
|
||||
bus.baseUrl = Discourse.getURL('/');
|
||||
}
|
||||
|
||||
if (user) {
|
||||
bus.callbackInterval = siteSettings.polling_interval;
|
||||
bus.enableLongPolling = true;
|
||||
|
||||
if (user.get('staff')) {
|
||||
bus.subscribe('/flagged_counts', (data) => {
|
||||
|
@ -58,7 +41,7 @@ export default {
|
|||
}, user.notification_channel_position);
|
||||
|
||||
bus.subscribe("/categories", function(data) {
|
||||
_.each(data.categories,function(c) {
|
||||
_.each(data.categories, function(c) {
|
||||
site.updateCategory(c);
|
||||
});
|
||||
_.each(data.deleted_categories,function(id) {
|
||||
|
@ -66,6 +49,10 @@ export default {
|
|||
});
|
||||
});
|
||||
|
||||
bus.subscribe("/client_settings", function(data) {
|
||||
siteSettings[data.name] = data.value;
|
||||
});
|
||||
|
||||
if (!Ember.testing) {
|
||||
initDesktopNotifications(bus);
|
||||
}
|
||||
|
|
|
@ -76,6 +76,10 @@ module SiteSettingExtension
|
|||
@refresh_settings ||= []
|
||||
end
|
||||
|
||||
def client_settings
|
||||
@client_settings ||= []
|
||||
end
|
||||
|
||||
def previews
|
||||
@previews ||= {}
|
||||
end
|
||||
|
@ -147,12 +151,7 @@ module SiteSettingExtension
|
|||
# just like a setting, except that it is available in javascript via DiscourseSession
|
||||
def client_setting(name, default = nil, opts = {})
|
||||
setting(name, default, opts)
|
||||
@client_settings ||= []
|
||||
@client_settings << name
|
||||
end
|
||||
|
||||
def client_settings
|
||||
@client_settings ||= []
|
||||
client_settings << name
|
||||
end
|
||||
|
||||
def settings_hash
|
||||
|
@ -323,6 +322,7 @@ module SiteSettingExtension
|
|||
|
||||
provider.save(name, val, type)
|
||||
current[name] = convert(val, type)
|
||||
notify_clients!(name) if client_settings.include? name
|
||||
clear_cache!
|
||||
end
|
||||
|
||||
|
@ -330,6 +330,10 @@ module SiteSettingExtension
|
|||
MessageBus.publish('/site_settings', {process: process_id})
|
||||
end
|
||||
|
||||
def notify_clients!(name)
|
||||
MessageBus.publish('/client_settings', {name: name, value: self.send(name)})
|
||||
end
|
||||
|
||||
def has_setting?(name)
|
||||
defaults.has_key?(name.to_sym) || defaults.has_key?("#{name}?".to_sym)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue