From b482b280d607192d86707ffe6086f43382e61588 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 2 Jan 2014 12:00:08 +1100 Subject: [PATCH] FEATURE: Basic backend support for muted and watched categories --- app/models/category_user.rb | 49 +++++++++++++++++++ app/models/topic_user.rb | 10 +++- .../20140101235747_add_category_users.rb | 9 ++++ lib/topic_creator.rb | 6 +++ spec/models/category_user_spec.rb | 31 ++++++++++++ spec/support/helpers.rb | 2 + 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 app/models/category_user.rb create mode 100644 db/migrate/20140101235747_add_category_users.rb create mode 100644 spec/models/category_user_spec.rb 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 = <