about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2021-04-17 15:41:57 +0200
committerGitHub <noreply@github.com>2021-04-17 15:41:57 +0200
commitca3bc1b09f344f38164aa65d2554cf50d5c10cc0 (patch)
tree9999129b8f3ae0b5015086aadb3675586e81e0e6 /app/lib
parent6d6000f61f7f611358a45efb3c557eb1e0a7e005 (diff)
Refactor StatusReachFinder to handle followers and relays as well (#16051)
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/status_reach_finder.rb25
1 files changed, 24 insertions, 1 deletions
diff --git a/app/lib/status_reach_finder.rb b/app/lib/status_reach_finder.rb
index 35b191dad..3aab3bde0 100644
--- a/app/lib/status_reach_finder.rb
+++ b/app/lib/status_reach_finder.rb
@@ -6,11 +6,22 @@ class StatusReachFinder
   end
 
   def inboxes
-    Account.where(id: reached_account_ids).inboxes
+    (reached_account_inboxes + followers_inboxes + relay_inboxes).uniq
   end
 
   private
 
+  def reached_account_inboxes
+    # When the status is a reblog, there are no interactions with it
+    # directly, we assume all interactions are with the original one
+
+    if @status.reblog?
+      []
+    else
+      Account.where(id: reached_account_ids).inboxes
+    end
+  end
+
   def reached_account_ids
     [
       replied_to_account_id,
@@ -49,4 +60,16 @@ class StatusReachFinder
   def replies_account_ids
     @status.replies.pluck(:account_id)
   end
+
+  def followers_inboxes
+    @status.account.followers.inboxes
+  end
+
+  def relay_inboxes
+    if @status.public_visibility?
+      Relay.enabled.pluck(:inbox_url)
+    else
+      []
+    end
+  end
 end