Skip to content

A platform for community discussion. Free, open, simple.

FIX: exclude topics from muted tag in category featured list. (#14925)

Vinoth Kannanc47a526371db
diff --git a/app/models/category_list.rb b/app/models/category_list.rb
index e092dabf42d..d6a1b67ed42 100644
--- a/app/models/category_list.rb
+++ b/app/models/category_list.rb
@@ -70,6 +70,7 @@ class CategoryList
.where('COALESCE(tu.notification_level,1) > :muted', muted: TopicUser.notification_levels[:muted])
end
+ @all_topics = TopicQuery.remove_muted_tags(@all_topics, @guardian.user)
@all_topics = @all_topics.includes(:last_poster) if @options[:include_topics]
@all_topics.each do |t|
# hint for the serializer
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index 7bef13f38fc..3175a6b1cf9 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -822,7 +822,7 @@ class TopicQuery
def remove_muted(list, user, options)
list = remove_muted_topics(list, user) unless options && options[:state] == "muted"
list = remove_muted_categories(list, user, exclude: options[:category])
- remove_muted_tags(list, user, options)
+ TopicQuery.remove_muted_tags(list, user, options)
end
def remove_muted_topics(list, user)
@@ -867,7 +867,7 @@ class TopicQuery
list
end
- def remove_muted_tags(list, user, opts = {})
+ def self.remove_muted_tags(list, user, opts = {})
if !SiteSetting.tagging_enabled || SiteSetting.remove_muted_tags_from_latest == 'never'
return list
end
diff --git a/lib/topic_query/private_message_lists.rb b/lib/topic_query/private_message_lists.rb
index 4f0c39ab605..592c1d701f4 100644
--- a/lib/topic_query/private_message_lists.rb
+++ b/lib/topic_query/private_message_lists.rb
@@ -39,7 +39,7 @@ class TopicQuery
def list_private_messages_new(user, type = :user)
list = filter_private_message_new(user, type)
- list = remove_muted_tags(list, user)
+ list = TopicQuery.remove_muted_tags(list, user)
list = remove_dismissed(list, user)
create_list(:private_messages, {}, list)
diff --git a/spec/models/category_list_spec.rb b/spec/models/category_list_spec.rb
index 5e8b8adcd97..ba90248b131 100644
--- a/spec/models/category_list_spec.rb
+++ b/spec/models/category_list_spec.rb
@@ -41,12 +41,16 @@ describe CategoryList do
secret_subcat.set_permissions(admins: :full)
secret_subcat.save
+ muted_tag = Fabricate(:tag) # muted tag
+ SiteSetting.default_tags_muted = muted_tag.name
+ Fabricate(:topic, category: public_cat, tags: [muted_tag])
+
CategoryFeaturedTopic.feature_topics
- expect(CategoryList.new(Guardian.new(admin), include_topics: true).categories.find { |x| x.name == public_cat.name }.displayable_topics.count).to eq(2)
+ expect(CategoryList.new(Guardian.new(admin), include_topics: true).categories.find { |x| x.name == public_cat.name }.displayable_topics.count).to eq(3)
expect(CategoryList.new(Guardian.new(admin), include_topics: true).categories.find { |x| x.name == private_cat.name }.displayable_topics.count).to eq(1)
- expect(CategoryList.new(Guardian.new(user), include_topics: true).categories.find { |x| x.name == public_cat.name }.displayable_topics.count).to eq(1)
+ expect(CategoryList.new(Guardian.new(user), include_topics: true).categories.find { |x| x.name == public_cat.name }.displayable_topics.count).to eq(2)
expect(CategoryList.new(Guardian.new(user), include_topics: true).categories.find { |x| x.name == private_cat.name }).to eq(nil)
expect(CategoryList.new(Guardian.new(nil), include_topics: true).categories.find { |x| x.name == public_cat.name }.displayable_topics.count).to eq(1)