mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -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
|
// We don't use the message bus in testing
|
||||||
if (Discourse.testing) { return; }
|
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 = {};
|
const deprecatedBus = {};
|
||||||
deprecatedBus.prototype = messageBus;
|
deprecatedBus.prototype = messageBus;
|
||||||
|
@ -20,5 +22,25 @@ export default {
|
||||||
messageBus.alwaysLongPoll = Discourse.Environment === "development";
|
messageBus.alwaysLongPoll = Discourse.Environment === "development";
|
||||||
messageBus.start();
|
messageBus.start();
|
||||||
Discourse.KeyValueStore.init("discourse_", messageBus);
|
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'),
|
siteSettings = container.lookup('site-settings:main'),
|
||||||
bus = container.lookup('message-bus: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) {
|
if (user) {
|
||||||
bus.callbackInterval = siteSettings.polling_interval;
|
|
||||||
bus.enableLongPolling = true;
|
|
||||||
|
|
||||||
if (user.get('staff')) {
|
if (user.get('staff')) {
|
||||||
bus.subscribe('/flagged_counts', (data) => {
|
bus.subscribe('/flagged_counts', (data) => {
|
||||||
|
@ -58,7 +41,7 @@ export default {
|
||||||
}, user.notification_channel_position);
|
}, user.notification_channel_position);
|
||||||
|
|
||||||
bus.subscribe("/categories", function(data) {
|
bus.subscribe("/categories", function(data) {
|
||||||
_.each(data.categories,function(c) {
|
_.each(data.categories, function(c) {
|
||||||
site.updateCategory(c);
|
site.updateCategory(c);
|
||||||
});
|
});
|
||||||
_.each(data.deleted_categories,function(id) {
|
_.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) {
|
if (!Ember.testing) {
|
||||||
initDesktopNotifications(bus);
|
initDesktopNotifications(bus);
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,10 @@ module SiteSettingExtension
|
||||||
@refresh_settings ||= []
|
@refresh_settings ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def client_settings
|
||||||
|
@client_settings ||= []
|
||||||
|
end
|
||||||
|
|
||||||
def previews
|
def previews
|
||||||
@previews ||= {}
|
@previews ||= {}
|
||||||
end
|
end
|
||||||
|
@ -147,12 +151,7 @@ module SiteSettingExtension
|
||||||
# just like a setting, except that it is available in javascript via DiscourseSession
|
# just like a setting, except that it is available in javascript via DiscourseSession
|
||||||
def client_setting(name, default = nil, opts = {})
|
def client_setting(name, default = nil, opts = {})
|
||||||
setting(name, default, opts)
|
setting(name, default, opts)
|
||||||
@client_settings ||= []
|
client_settings << name
|
||||||
@client_settings << name
|
|
||||||
end
|
|
||||||
|
|
||||||
def client_settings
|
|
||||||
@client_settings ||= []
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def settings_hash
|
def settings_hash
|
||||||
|
@ -323,6 +322,7 @@ module SiteSettingExtension
|
||||||
|
|
||||||
provider.save(name, val, type)
|
provider.save(name, val, type)
|
||||||
current[name] = convert(val, type)
|
current[name] = convert(val, type)
|
||||||
|
notify_clients!(name) if client_settings.include? name
|
||||||
clear_cache!
|
clear_cache!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -330,6 +330,10 @@ module SiteSettingExtension
|
||||||
MessageBus.publish('/site_settings', {process: process_id})
|
MessageBus.publish('/site_settings', {process: process_id})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notify_clients!(name)
|
||||||
|
MessageBus.publish('/client_settings', {name: name, value: self.send(name)})
|
||||||
|
end
|
||||||
|
|
||||||
def has_setting?(name)
|
def has_setting?(name)
|
||||||
defaults.has_key?(name.to_sym) || defaults.has_key?("#{name}?".to_sym)
|
defaults.has_key?(name.to_sym) || defaults.has_key?("#{name}?".to_sym)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue