From 1f99d862874fc1976b2a462dda01d1dc03d98e34 Mon Sep 17 00:00:00 2001
From: Claire <claire.github-309c@sitedethib.com>
Date: Wed, 6 Sep 2023 21:04:48 +0200
Subject: [PATCH] Fix blocked domain appears from account feed (#26823)

Co-authored-by: Jeong Arm <kjwonmail@gmail.com>
Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
---
 app/lib/account_statuses_filter.rb          |  9 ++++++++-
 spec/models/account_statuses_filter_spec.rb | 14 ++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/app/lib/account_statuses_filter.rb b/app/lib/account_statuses_filter.rb
index c6dc1385f5..a5aca96601 100644
--- a/app/lib/account_statuses_filter.rb
+++ b/app/lib/account_statuses_filter.rb
@@ -55,7 +55,14 @@ class AccountStatusesFilter
   end
 
   def filtered_reblogs_scope
-    Status.left_outer_joins(:reblog).where(reblog_of_id: nil).or(Status.where.not(reblogs_statuses: { account_id: current_account.excluded_from_timeline_account_ids }))
+    scope = Status.left_outer_joins(reblog: :account)
+    scope
+      .where(reblog_of_id: nil)
+      .or(
+        scope
+          .where.not(reblog: { account_id: current_account.excluded_from_timeline_account_ids })
+          .where.not(reblog: { accounts: { domain: current_account.excluded_from_timeline_domains } })
+      )
   end
 
   def only_media_scope
diff --git a/spec/models/account_statuses_filter_spec.rb b/spec/models/account_statuses_filter_spec.rb
index fa7664d921..0cf6453fe3 100644
--- a/spec/models/account_statuses_filter_spec.rb
+++ b/spec/models/account_statuses_filter_spec.rb
@@ -199,6 +199,20 @@ RSpec.describe AccountStatusesFilter do
         end
       end
 
+      context 'when blocking a reblogged domain' do
+        let(:other_account) { Fabricate(:account, domain: 'example.com') }
+        let(:reblogging_status) { Fabricate(:status, account: other_account) }
+        let(:reblog) { Fabricate(:status, account: account, visibility: 'public', reblog: reblogging_status) }
+
+        before do
+          current_account.block_domain!(other_account.domain)
+        end
+
+        it 'does not return reblog of blocked domain' do
+          expect(subject.results.pluck(:id)).to_not include(reblog.id)
+        end
+      end
+
       context 'when muting a reblogged account' do
         let(:reblog) { status_with_reblog!('public') }