aboutsummaryrefslogtreecommitdiff
path: root/app/lib/status_reach_finder.rb
diff options
context:
space:
mode:
authorTakeshi Umeda <noel.yoshiba@gmail.com>2021-01-10 11:17:55 +0900
committerGitHub <noreply@github.com>2021-01-10 11:17:55 +0900
commit98a2603dc163210d3a0aab0a0c2b8ef74c7e5eb0 (patch)
tree761694d2d697c58faf02a3ff9ef26bf045fc0274 /app/lib/status_reach_finder.rb
parent7cd4ed7d4298626d2b141cd6d8378e95bc248824 (diff)
parent087ed84367537ac168ed3e00bb7eb4bd582dc3d0 (diff)
downloadmastodon-feature-limited-visibility-bearcaps.tar
mastodon-feature-limited-visibility-bearcaps.tar.gz
mastodon-feature-limited-visibility-bearcaps.tar.bz2
mastodon-feature-limited-visibility-bearcaps.zip
Merge branch 'master' into feature-limited-visibility-bearcapsfeature-limited-visibility-bearcaps
Diffstat (limited to 'app/lib/status_reach_finder.rb')
-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