Files
mastodon/app/lib/status_reach_finder.rb
jcoffey-dev 319ed76dbd
Crowdin / Upload translations / upload-translations (push) Skipped
Historical data migration test / test (14-alpine) (push) Canceled after 0s
Historical data migration test / test (15-alpine) (push) Canceled after 0s
Historical data migration test / test (16-alpine) (push) Canceled after 0s
Historical data migration test / test (17-alpine) (push) Canceled after 0s
Bundler Audit / security (push) Canceled after 0s
Haml Linting / lint (push) Canceled after 0s
JavaScript Linting / lint (push) Canceled after 0s
Ruby Linting / lint (push) Canceled after 0s
JavaScript Testing / test (push) Canceled after 0s
Ruby Testing / build (production) (push) Canceled after 0s
Ruby Testing / test (.ruby-version) (push) Canceled after 0s
Ruby Testing / test (3.3) (push) Canceled after 0s
Ruby Testing / test (3.4) (push) Canceled after 0s
Ruby Testing / End to End testing (.ruby-version) (push) Canceled after 0s
Ruby Testing / End to End testing (3.3) (push) Canceled after 0s
Ruby Testing / End to End testing (3.4) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check i18n / check-i18n (push) Canceled after 0s
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (javascript) (push) Canceled after 0s
CodeQL / Analyze (ruby) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.3, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (3.4, docker.elastic.co/elasticsearch/elasticsearch:7.17.29) (push) Canceled after 0s
Check formatting / lint (push) Canceled after 0s
CSS Linting / lint (push) Canceled after 0s
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.19.2) (push) Canceled after 0s
Chromatic / Check for relevant changes (push) Canceled after 0s
Chromatic / Run Chromatic (push) Canceled after 0s
Import Mastodon v4.7.3
Snapshot of upstream tag v4.7.3 (commit 8ff11c2bb7b9f0714e947b10fa3629c6542c7121) from
https://github.com/mastodon/mastodon, unmodified.
2026-10-05 22:03:13 -07:00

119 lines
2.9 KiB
Ruby

# frozen_string_literal: true
class StatusReachFinder
# @param [Status] status
# @param [Hash] options
# @option options [Boolean] :unsafe
def initialize(status, options = {})
@status = status
@options = options
end
def inboxes
(reached_account_inboxes + followers_inboxes + relay_inboxes).uniq
end
private
def reached_account_inboxes
scope = Account.where(id: reached_account_ids)
inboxes_without_suspended_for(scope)
end
def reached_account_ids
# 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?
[reblog_of_account_id]
else
[
replied_to_account_id,
reblog_of_account_id,
quote_of_account_id,
mentioned_account_ids,
reblogs_account_ids,
quotes_account_ids,
favourites_account_ids,
replies_account_ids,
].tap do |arr|
arr.flatten!
arr.compact!
arr.uniq!
end
end
end
def replied_to_account_id
@status.in_reply_to_account_id if distributable?
end
def quote_of_account_id
@status.quote&.quoted_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
# Beware: Quotes can be created without the author having had access to the status
def quotes_account_ids
@status.quotes.pluck(:account_id) if distributable? || unsafe?
end
# Beware: Reblogs can be created without the author having had access to the status
def reblogs_account_ids
@status.reblogs.rewhere(deleted_at: [nil, @status.deleted_at]).pluck(:account_id) if distributable? || unsafe?
end
# Beware: Favourites can be created without the author having had access to the status
def favourites_account_ids
@status.favourites.pluck(:account_id) if distributable? || unsafe?
end
# Beware: Replies can be created without the author having had access to the status
def replies_account_ids
@status.replies.pluck(:account_id) if distributable? || unsafe?
end
def followers_inboxes
scope = followers_scope
inboxes_without_suspended_for(scope)
end
def relay_inboxes
if @status.public_visibility?
Relay.enabled.pluck(:inbox_url)
else
[]
end
end
def distributable?
@status.public_visibility? || @status.unlisted_visibility?
end
def unsafe?
@options[:unsafe]
end
def followers_scope
if @status.in_reply_to_local_account? && distributable?
@status.account.followers.or(@status.thread.account.followers.not_domain_blocked_by_account(@status.account))
elsif @status.direct_visibility? || @status.limited_visibility?
Account.none
else
@status.account.followers
end
end
def inboxes_without_suspended_for(scope)
scope.merge!(Account.without_suspended) unless unsafe?
scope.inboxes
end
end