2021-04-17 21:55:46 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class AccountReachFinder
|
2024-11-12 17:38:08 +09:00
|
|
|
RECENT_LIMIT = 2_000
|
|
|
|
STATUS_LIMIT = 200
|
|
|
|
STATUS_SINCE = 2.days
|
|
|
|
|
2021-04-17 21:55:46 +09:00
|
|
|
def initialize(account)
|
|
|
|
@account = account
|
|
|
|
end
|
|
|
|
|
|
|
|
def inboxes
|
2023-05-12 20:13:04 +09:00
|
|
|
(followers_inboxes + reporters_inboxes + recently_mentioned_inboxes + relay_inboxes).uniq
|
2021-04-17 21:55:46 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def followers_inboxes
|
|
|
|
@account.followers.inboxes
|
|
|
|
end
|
|
|
|
|
|
|
|
def reporters_inboxes
|
|
|
|
Account.where(id: @account.targeted_reports.select(:account_id)).inboxes
|
|
|
|
end
|
|
|
|
|
2023-05-12 20:13:04 +09:00
|
|
|
def recently_mentioned_inboxes
|
2024-11-12 17:38:08 +09:00
|
|
|
Account
|
|
|
|
.joins(:mentions)
|
|
|
|
.where(mentions: { status: recent_statuses })
|
|
|
|
.inboxes
|
|
|
|
.take(RECENT_LIMIT)
|
2023-05-12 20:13:04 +09:00
|
|
|
end
|
|
|
|
|
2021-04-17 21:55:46 +09:00
|
|
|
def relay_inboxes
|
|
|
|
Relay.enabled.pluck(:inbox_url)
|
|
|
|
end
|
2024-11-12 17:38:08 +09:00
|
|
|
|
|
|
|
def oldest_status_id
|
|
|
|
Mastodon::Snowflake
|
|
|
|
.id_at(STATUS_SINCE.ago, with_random: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def recent_statuses
|
|
|
|
@account
|
|
|
|
.statuses
|
|
|
|
.recent
|
|
|
|
.where(id: oldest_status_id...)
|
|
|
|
.limit(STATUS_LIMIT)
|
|
|
|
end
|
2021-04-17 21:55:46 +09:00
|
|
|
end
|