FEATURE: correct muted category implementation
- Don't change tracking state on muted categories - Exclude muted sub categories from parent
This commit is contained in:
parent
b0f8b104d2
commit
dc0266cc22
|
@ -60,15 +60,6 @@ class CategoryUser < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def self.apply_default_to_topic(topic, level, reason)
|
def self.apply_default_to_topic(topic, level, reason)
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
class DontAutoMutoTopics < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
# muting all new topics was a mistake, revert it
|
||||||
|
execute 'DELETE FROM topic_users WHERE notification_level = 0 and notifications_reason_id =7 AND first_visited_at IS NULL'
|
||||||
|
|
||||||
|
execute 'UPDATE topic_users SET notification_level = 1,
|
||||||
|
notifications_reason_id = NULL
|
||||||
|
WHERE notification_level = 0 AND notifications_reason_id =7'
|
||||||
|
end
|
||||||
|
end
|
|
@ -19,17 +19,12 @@ class TopicCreator
|
||||||
process_private_message
|
process_private_message
|
||||||
save_topic
|
save_topic
|
||||||
watch_topic
|
watch_topic
|
||||||
auto_mute_topic
|
|
||||||
|
|
||||||
@topic
|
@topic
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def auto_mute_topic
|
|
||||||
CategoryUser.auto_mute_new_topic(@topic)
|
|
||||||
end
|
|
||||||
|
|
||||||
def watch_topic
|
def watch_topic
|
||||||
unless @opts[:auto_track] == false
|
unless @opts[:auto_track] == false
|
||||||
@topic.notifier.watch_topic!(@topic.user_id)
|
@topic.notifier.watch_topic!(@topic.user_id)
|
||||||
|
|
|
@ -210,6 +210,13 @@ class TopicQuery
|
||||||
result.order("topics.#{sort_column} #{sort_dir}")
|
result.order("topics.#{sort_column} #{sort_dir}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_category_id(category_id_or_slug)
|
||||||
|
return nil unless category_id_or_slug
|
||||||
|
category_id = category_id_or_slug.to_i
|
||||||
|
category_id = Category.where(slug: category_id_or_slug).pluck(:id).first if category_id == 0
|
||||||
|
category_id
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# Create results based on a bunch of default options
|
# Create results based on a bunch of default options
|
||||||
def default_results(options={})
|
def default_results(options={})
|
||||||
|
@ -224,11 +231,7 @@ class TopicQuery
|
||||||
.references('tu')
|
.references('tu')
|
||||||
end
|
end
|
||||||
|
|
||||||
category_id = nil
|
category_id = get_category_id(options[:category])
|
||||||
if options[:category].present?
|
|
||||||
category_id = options[:category].to_i
|
|
||||||
category_id = Category.where(slug: options[:category]).pluck(:id).first if category_id == 0
|
|
||||||
|
|
||||||
if category_id
|
if category_id
|
||||||
if options[:no_subcategories]
|
if options[:no_subcategories]
|
||||||
result = result.where('categories.id = ?', category_id)
|
result = result.where('categories.id = ?', category_id)
|
||||||
|
@ -237,7 +240,6 @@ class TopicQuery
|
||||||
end
|
end
|
||||||
result = result.references(:categories)
|
result = result.references(:categories)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
result = apply_ordering(result, options)
|
result = apply_ordering(result, options)
|
||||||
result = result.listable_topics.includes(category: :topic_only_relative_url)
|
result = result.listable_topics.includes(category: :topic_only_relative_url)
|
||||||
|
@ -287,18 +289,25 @@ class TopicQuery
|
||||||
|
|
||||||
def latest_results(options={})
|
def latest_results(options={})
|
||||||
result = default_results(options)
|
result = default_results(options)
|
||||||
result = remove_muted_categories(result, @user) unless options[:category].present?
|
result = remove_muted_categories(result, @user, exclude: options[:category])
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_muted_categories(list, user)
|
def remove_muted_categories(list, user, opts)
|
||||||
|
category_id = get_category_id(opts[:exclude]) if opts
|
||||||
if user
|
if user
|
||||||
list = list.where("NOT EXISTS(
|
list = list.where("NOT EXISTS(
|
||||||
SELECT 1 FROM category_users cu
|
SELECT 1 FROM category_users cu
|
||||||
WHERE cu.user_id = ? AND
|
WHERE cu.user_id = ? AND
|
||||||
cu.category_id = topics.category_id AND
|
cu.category_id = topics.category_id AND
|
||||||
cu.notification_level = ?
|
cu.notification_level = ? AND
|
||||||
)", user.id, CategoryUser.notification_levels[:muted]).references('cu')
|
cu.category_id <> ?
|
||||||
|
)",
|
||||||
|
user.id,
|
||||||
|
CategoryUser.notification_levels[:muted],
|
||||||
|
category_id || -1
|
||||||
|
)
|
||||||
|
.references('cu')
|
||||||
end
|
end
|
||||||
|
|
||||||
list
|
list
|
||||||
|
@ -314,7 +323,7 @@ class TopicQuery
|
||||||
|
|
||||||
def new_results(options={})
|
def new_results(options={})
|
||||||
result = TopicQuery.new_filter(default_results(options.reverse_merge(:unordered => true)), @user.treat_as_new_topic_start_date)
|
result = TopicQuery.new_filter(default_results(options.reverse_merge(:unordered => true)), @user.treat_as_new_topic_start_date)
|
||||||
result = remove_muted_categories(result, @user) unless options[:category].present?
|
result = remove_muted_categories(result, @user, exclude: options[:category])
|
||||||
suggested_ordering(result, options)
|
suggested_ordering(result, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,6 @@ describe CategoryUser do
|
||||||
tu.notification_level.should == TopicUser.notification_levels[:tracking]
|
tu.notification_level.should == TopicUser.notification_levels[:tracking]
|
||||||
tu.notifications_reason_id.should == TopicUser.notification_reasons[:auto_track_category]
|
tu.notifications_reason_id.should == TopicUser.notification_reasons[:auto_track_category]
|
||||||
|
|
||||||
tu = TopicUser.get(muted_post.topic, user)
|
|
||||||
tu.notification_level.should == TopicUser.notification_levels[:muted]
|
|
||||||
tu.notifications_reason_id.should == TopicUser.notification_reasons[:auto_mute_category]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue