Refactor StatusReachFinder to be used in more places
This commit is contained in:
parent
c99d28369a
commit
ce463ccb50
13 changed files with 321 additions and 99 deletions
|
@ -1,10 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class StatusReachFinder
|
||||
def initialize(status)
|
||||
@status = status
|
||||
DEFAULT_OPTIONS = {
|
||||
with_parent: true,
|
||||
}.freeze
|
||||
|
||||
# @param [Status] status
|
||||
# @param [Hash] options
|
||||
# @option [Boolean] with_parent
|
||||
def initialize(status, options = {})
|
||||
@status = status
|
||||
@options = DEFAULT_OPTIONS.merge(options)
|
||||
end
|
||||
|
||||
# @return [Array<String>]
|
||||
def inboxes
|
||||
(reached_account_inboxes + followers_inboxes + relay_inboxes).uniq
|
||||
end
|
||||
|
@ -15,11 +24,15 @@ class StatusReachFinder
|
|||
# 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
|
||||
return [] if @status.reblog?
|
||||
|
||||
# If a status is a reply to a local status, we also want to send
|
||||
# it everywhere the parent status was sent
|
||||
|
||||
arr = []
|
||||
arr.concat(self.class.new(@status.thread, with_parent: false).inboxes) if @status.in_reply_to_local_account? && @options[:with_parent]
|
||||
arr.concat(Account.where(id: reached_account_ids).inboxes)
|
||||
arr
|
||||
end
|
||||
|
||||
def reached_account_ids
|
||||
|
@ -28,6 +41,7 @@ class StatusReachFinder
|
|||
reblog_of_account_id,
|
||||
mentioned_account_ids,
|
||||
reblogs_account_ids,
|
||||
reblogger_follower_account_ids,
|
||||
favourites_account_ids,
|
||||
replies_account_ids,
|
||||
].tap do |arr|
|
||||
|
@ -38,7 +52,7 @@ class StatusReachFinder
|
|||
end
|
||||
|
||||
def replied_to_account_id
|
||||
@status.in_reply_to_account_id
|
||||
@status.in_reply_to_account_id if @status.local?
|
||||
end
|
||||
|
||||
def reblog_of_account_id
|
||||
|
@ -46,27 +60,27 @@ class StatusReachFinder
|
|||
end
|
||||
|
||||
def mentioned_account_ids
|
||||
@status.mentions.pluck(:account_id)
|
||||
@status.mentions.pluck(:account_id) if @status.local?
|
||||
end
|
||||
|
||||
def reblogs_account_ids
|
||||
@status.reblogs.pluck(:account_id)
|
||||
@reblogs_account_ids ||= @status.reblogs.pluck(:account_id)
|
||||
end
|
||||
|
||||
def reblogger_follower_account_ids
|
||||
Follow.where(target_account_id: reblogs_account_ids).pluck(:account_id)
|
||||
end
|
||||
|
||||
def favourites_account_ids
|
||||
@status.favourites.pluck(:account_id)
|
||||
@status.favourites.pluck(:account_id) if @status.local?
|
||||
end
|
||||
|
||||
def replies_account_ids
|
||||
@status.replies.pluck(:account_id)
|
||||
@status.replies.pluck(:account_id) if @status.local?
|
||||
end
|
||||
|
||||
def followers_inboxes
|
||||
if @status.in_reply_to_local_account? && @status.distributable?
|
||||
@status.account.followers.or(@status.thread.account.followers).inboxes
|
||||
else
|
||||
@status.account.followers.inboxes
|
||||
end
|
||||
@status.account.followers.inboxes
|
||||
end
|
||||
|
||||
def relay_inboxes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue