diff --git a/app/models/category_user.rb b/app/models/category_user.rb new file mode 100644 index 00000000000..aef7760284c --- /dev/null +++ b/app/models/category_user.rb @@ -0,0 +1,49 @@ +class CategoryUser < ActiveRecord::Base + belongs_to :category + belongs_to :user + + # same for now + def self.notification_levels + TopicUser.notification_levels + end + + def self.auto_watch_new_topic(topic) + apply_default_to_topic( + topic, + TopicUser.notification_levels[:watching], + TopicUser.notification_reasons[:auto_watch_category] + ) + end + + def self.auto_mute_new_topic(topic) + apply_default_to_topic( + topic, + TopicUser.notification_levels[:muted], + TopicUser.notification_reasons[:auto_mute_category] + ) + end + + private + + def self.apply_default_to_topic(topic, level, reason) + # Can not afford to slow down creation of topics when a pile of users are watching new topics, reverting to SQL for max perf here + sql = <