FIX: default_tags_muted setting should work for anonymous users too.

FIX: default_tags_muted setting should work for anonymous users too.

diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index df2e60f..bef2eb3 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 86e18d1..d36b7cd 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) }

GitHub sha: 89fcb75a

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/mute-tag-in-settings-seems-to-be-broken-the-muted-tag-topics-still-show-up-in-the-latest/159893/13