From 1e75eb690d6599b94a2c0bd66b255529028f6f92 Mon Sep 17 00:00:00 2001
From: Claire <claire.github-309c@sitedethib.com>
Date: Wed, 3 May 2023 19:17:40 +0200
Subject: [PATCH] Fix own posts not getting delivered to own lists (#24810)

---
 app/models/concerns/account_interactions.rb       | 4 ++--
 spec/models/concerns/account_interactions_spec.rb | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/app/models/concerns/account_interactions.rb b/app/models/concerns/account_interactions.rb
index cda221c432..3c64ebd9fa 100644
--- a/app/models/concerns/account_interactions.rb
+++ b/app/models/concerns/account_interactions.rb
@@ -271,8 +271,8 @@ module AccountInteractions
   end
 
   def lists_for_local_distribution
-    lists.joins(account: :user)
-         .where.not(list_accounts: { follow_id: nil })
+    scope = lists.joins(account: :user)
+    scope.where.not(list_accounts: { follow_id: nil }).or(scope.where(account_id: id))
          .where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago)
   end
 
diff --git a/spec/models/concerns/account_interactions_spec.rb b/spec/models/concerns/account_interactions_spec.rb
index 7984576161..8e3f6f5608 100644
--- a/spec/models/concerns/account_interactions_spec.rb
+++ b/spec/models/concerns/account_interactions_spec.rb
@@ -685,6 +685,7 @@ describe AccountInteractions do
   end
 
   describe '#lists_for_local_distribution' do
+    let(:account)                 { Fabricate(:user, current_sign_in_at: Time.now.utc).account }
     let!(:inactive_follower_user) { Fabricate(:user, current_sign_in_at: 5.years.ago) }
     let!(:follower_user)          { Fabricate(:user, current_sign_in_at: Time.now.utc) }
     let!(:follow_request_user)    { Fabricate(:user, current_sign_in_at: Time.now.utc) }
@@ -693,6 +694,8 @@ describe AccountInteractions do
     let!(:follower_list)          { Fabricate(:list, account: follower_user.account) }
     let!(:follow_request_list)    { Fabricate(:list, account: follow_request_user.account) }
 
+    let!(:self_list)              { Fabricate(:list, account: account) }
+
     before do
       inactive_follower_user.account.follow!(account)
       follower_user.account.follow!(account)
@@ -701,10 +704,11 @@ describe AccountInteractions do
       inactive_follower_list.accounts << account
       follower_list.accounts << account
       follow_request_list.accounts << account
+      self_list.accounts << account
     end
 
-    it 'includes only the list from the active follower' do
-      expect(account.lists_for_local_distribution.to_a).to eq [follower_list]
+    it 'includes only the list from the active follower and from oneself' do
+      expect(account.lists_for_local_distribution.to_a).to contain_exactly(follower_list, self_list)
     end
   end
 end
-- 
GitLab