~cytrogen/masto-fe

ref: 53f5b27bd10e5f471b59cd0597d67ea12587c95a masto-fe/app/lib/account_reach_finder.rb -rw-r--r-- 770 bytes
53f5b27b — Claire Merge commit '640421f661ee4d7e76a2aab607e7b15687940b6f' into glitch-soc/merge-upstream 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

class AccountReachFinder
  def initialize(account)
    @account = account
  end

  def inboxes
    (followers_inboxes + reporters_inboxes + recently_mentioned_inboxes + relay_inboxes).uniq
  end

  private

  def followers_inboxes
    @account.followers.inboxes
  end

  def reporters_inboxes
    Account.where(id: @account.targeted_reports.select(:account_id)).inboxes
  end

  def recently_mentioned_inboxes
    cutoff_id       = Mastodon::Snowflake.id_at(2.days.ago, with_random: false)
    recent_statuses = @account.statuses.recent.where(id: cutoff_id...).limit(200)

    Account.joins(:mentions).where(mentions: { status: recent_statuses }).inboxes.take(2000)
  end

  def relay_inboxes
    Relay.enabled.pluck(:inbox_url)
  end
end