2020-11-27 14:48:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusReachFinder
|
2022-01-19 21:37:27 +00:00
|
|
|
# @param [Status] status
|
|
|
|
# @param [Hash] options
|
|
|
|
# @option options [Boolean] :unsafe
|
|
|
|
def initialize(status, options = {})
|
|
|
|
@status = status
|
|
|
|
@options = options
|
2020-11-27 14:48:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def inboxes
|
2021-04-17 13:41:57 +00:00
|
|
|
(reached_account_inboxes + followers_inboxes + relay_inboxes).uniq
|
2020-11-27 14:48:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-04-17 13:41:57 +00:00
|
|
|
def reached_account_inboxes
|
2024-01-12 15:58:28 +00:00
|
|
|
Account.where(id: reached_account_ids).inboxes
|
|
|
|
end
|
|
|
|
|
|
|
|
def reached_account_ids
|
2021-04-17 13:41:57 +00:00
|
|
|
# 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?
|
2024-01-12 15:58:28 +00:00
|
|
|
[reblog_of_account_id]
|
2021-04-17 13:41:57 +00:00
|
|
|
else
|
2024-01-12 15:58:28 +00:00
|
|
|
[
|
|
|
|
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
|
2020-11-27 14:48:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def replied_to_account_id
|
2022-01-19 21:37:27 +00:00
|
|
|
@status.in_reply_to_account_id if distributable?
|
2020-11-27 14:48:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def reblog_of_account_id
|
|
|
|
@status.reblog.account_id if @status.reblog?
|
|
|
|
end
|
|
|
|
|
|
|
|
def mentioned_account_ids
|
|
|
|
@status.mentions.pluck(:account_id)
|
|
|
|
end
|
|
|
|
|
2022-01-19 21:37:27 +00:00
|
|
|
# Beware: Reblogs can be created without the author having had access to the status
|
2020-11-27 14:48:31 +00:00
|
|
|
def reblogs_account_ids
|
2022-11-04 15:31:44 +00:00
|
|
|
@status.reblogs.rewhere(deleted_at: [nil, @status.deleted_at]).pluck(:account_id) if distributable? || unsafe?
|
2020-11-27 14:48:31 +00:00
|
|
|
end
|
|
|
|
|
2022-01-19 21:37:27 +00:00
|
|
|
# Beware: Favourites can be created without the author having had access to the status
|
2020-11-27 14:48:31 +00:00
|
|
|
def favourites_account_ids
|
2022-01-19 21:37:27 +00:00
|
|
|
@status.favourites.pluck(:account_id) if distributable? || unsafe?
|
2020-11-27 14:48:31 +00:00
|
|
|
end
|
|
|
|
|
2022-01-19 21:37:27 +00:00
|
|
|
# Beware: Replies can be created without the author having had access to the status
|
2020-11-27 14:48:31 +00:00
|
|
|
def replies_account_ids
|
2022-01-19 21:37:27 +00:00
|
|
|
@status.replies.pluck(:account_id) if distributable? || unsafe?
|
2020-11-27 14:48:31 +00:00
|
|
|
end
|
2021-04-17 13:41:57 +00:00
|
|
|
|
|
|
|
def followers_inboxes
|
2022-01-19 21:37:27 +00:00
|
|
|
if @status.in_reply_to_local_account? && distributable?
|
2022-12-15 14:52:06 +00:00
|
|
|
@status.account.followers.or(@status.thread.account.followers.not_domain_blocked_by_account(@status.account)).inboxes
|
2022-01-19 21:37:27 +00:00
|
|
|
elsif @status.direct_visibility? || @status.limited_visibility?
|
|
|
|
[]
|
2021-04-22 12:26:11 +00:00
|
|
|
else
|
|
|
|
@status.account.followers.inboxes
|
|
|
|
end
|
2021-04-17 13:41:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def relay_inboxes
|
|
|
|
if @status.public_visibility?
|
|
|
|
Relay.enabled.pluck(:inbox_url)
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
2022-01-19 21:37:27 +00:00
|
|
|
|
|
|
|
def distributable?
|
|
|
|
@status.public_visibility? || @status.unlisted_visibility?
|
|
|
|
end
|
|
|
|
|
|
|
|
def unsafe?
|
|
|
|
@options[:unsafe]
|
|
|
|
end
|
2020-11-27 14:48:31 +00:00
|
|
|
end
|