Skip to content

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

FIX: default_tags_muted setting should work for anonymous users too.

Vinoth Kannan89fcb75af2b8
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index df2e60f42e2..bef2eb3f24f 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -908,11 +908,18 @@ class TopicQuery
end
def remove_muted_tags(list, user, opts = nil)
- if user.nil? || !SiteSetting.tagging_enabled || SiteSetting.remove_muted_tags_from_latest == 'never'
+ if !SiteSetting.tagging_enabled || SiteSetting.remove_muted_tags_from_latest == 'never'
return list
end
- muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id)
+ muted_tag_ids = []
+
+ if user.present?
+ muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id)
+ else
+ muted_tag_ids = SiteSetting.default_tags_muted.split("|").map(&:to_i)
+ end
+
if muted_tag_ids.blank?
return list
end
diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb
index 86e18d1fac4..d36b7cd81e2 100644
--- a/spec/components/topic_query_spec.rb
+++ b/spec/components/topic_query_spec.rb
@@ -281,6 +281,19 @@ describe TopicQuery do
end
end
+ context 'remove_muted_tags' do
+ fab!(:topic) { Fabricate(:topic, tags: [tag]) }
+
+ before do
+ SiteSetting.remove_muted_tags_from_latest = 'always'
+ SiteSetting.default_tags_muted = tag.id.to_s
+ end
+
+ it 'removes default muted tag topics for anonymous users' do
+ expect(TopicQuery.new(nil).list_latest.topics.map(&:id)).not_to include(topic.id)
+ end
+ end
+
context "and categories too" do
let(:category1) { Fabricate(:category_with_definition) }
let(:category2) { Fabricate(:category_with_definition) }