mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
Use message bus to broadcast addition and removal of categories
This commit is contained in:
parent
229395729d
commit
c0f3c47196
2 changed files with 11 additions and 0 deletions
|
@ -69,6 +69,11 @@ Discourse = Ember.Application.createWithMixins({
|
|||
user.set('unread_notifications', data.unread_notifications);
|
||||
user.set('unread_private_messages', data.unread_private_messages);
|
||||
}), user.notification_channel_position);
|
||||
bus.subscribe("/categories", function(data){
|
||||
Discourse.get('site').set('categories', data.categories.map(function(c){
|
||||
return Discourse.Category.create(c);
|
||||
}));
|
||||
});
|
||||
}
|
||||
}.observes('currentUser'),
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@ class Category < ActiveRecord::Base
|
|||
before_validation :ensure_slug
|
||||
after_save :invalidate_site_cache
|
||||
after_create :create_category_definition
|
||||
after_create :publish_categories_list
|
||||
after_destroy :invalidate_site_cache
|
||||
after_destroy :publish_categories_list
|
||||
|
||||
scope :latest, ->{ order('topic_count desc') }
|
||||
|
||||
|
@ -55,6 +57,10 @@ class Category < ActiveRecord::Base
|
|||
Site.invalidate_cache
|
||||
end
|
||||
|
||||
def publish_categories_list
|
||||
MessageBus.publish('/categories', {categories: ActiveModel::ArraySerializer.new(Category.latest.all).as_json})
|
||||
end
|
||||
|
||||
def uncategorized_validator
|
||||
errors.add(:name, I18n.t(:is_reserved)) if name == SiteSetting.uncategorized_name
|
||||
errors.add(:slug, I18n.t(:is_reserved)) if slug == SiteSetting.uncategorized_name
|
||||
|
|
Loading…
Reference in a new issue