about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2020-12-05 17:33:29 +0100
committerClaire <claire.github-309c@sitedethib.com>2020-12-05 17:33:37 +0100
commitf8d867bac43e7e18d293ac32a9be597d1f46dce3 (patch)
treeb3d950a01a8dee5403081f56cf0c6b0571954e90 /app/lib
parent13df125b6c75923ccc21a5c57053e680cea75f38 (diff)
parent44d5c6bc8ffd92cd201380dabe35748e50b6af68 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- `app/services/remove_status_service.rb`:
  Conflict caused by us having a distinc Direct timeline.
  Ported upstream changes.
- `app/javascript/mastodon/features/compose/components/compose_form.js`:
  Conflict between glitch-soc's variable character limit and upstream
  refactoring that part of the code.
  Ported upstream changes.
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/status_reach_finder.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/app/lib/status_reach_finder.rb b/app/lib/status_reach_finder.rb
new file mode 100644
index 000000000..35b191dad
--- /dev/null
+++ b/app/lib/status_reach_finder.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+class StatusReachFinder
+  def initialize(status)
+    @status = status
+  end
+
+  def inboxes
+    Account.where(id: reached_account_ids).inboxes
+  end
+
+  private
+
+  def reached_account_ids
+    [
+      replied_to_account_id,
+      reblog_of_account_id,
+      mentioned_account_ids,
+      reblogs_account_ids,
+      favourites_account_ids,
+      replies_account_ids,
+    ].tap do |arr|
+      arr.flatten!
+      arr.compact!
+      arr.uniq!
+    end
+  end
+
+  def replied_to_account_id
+    @status.in_reply_to_account_id
+  end
+
+  def reblog_of_account_id
+    @status.reblog.account_id if @status.reblog?
+  end
+
+  def mentioned_account_ids
+    @status.mentions.pluck(:account_id)
+  end
+
+  def reblogs_account_ids
+    @status.reblogs.pluck(:account_id)
+  end
+
+  def favourites_account_ids
+    @status.favourites.pluck(:account_id)
+  end
+
+  def replies_account_ids
+    @status.replies.pluck(:account_id)
+  end
+end