account_reach_finder.rb 954 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # frozen_string_literal: true
  2. class AccountReachFinder
  3. RECENT_LIMIT = 2_000
  4. STATUS_LIMIT = 200
  5. STATUS_SINCE = 2.days
  6. def initialize(account)
  7. @account = account
  8. end
  9. def inboxes
  10. (followers_inboxes + reporters_inboxes + recently_mentioned_inboxes + relay_inboxes).uniq
  11. end
  12. private
  13. def followers_inboxes
  14. @account.followers.inboxes
  15. end
  16. def reporters_inboxes
  17. Account.where(id: @account.targeted_reports.select(:account_id)).inboxes
  18. end
  19. def recently_mentioned_inboxes
  20. Account
  21. .joins(:mentions)
  22. .where(mentions: { status: recent_statuses })
  23. .inboxes
  24. .take(RECENT_LIMIT)
  25. end
  26. def relay_inboxes
  27. Relay.enabled.pluck(:inbox_url)
  28. end
  29. def oldest_status_id
  30. Mastodon::Snowflake
  31. .id_at(STATUS_SINCE.ago, with_random: false)
  32. end
  33. def recent_statuses
  34. @account
  35. .statuses
  36. .recent
  37. .where(id: oldest_status_id...)
  38. .limit(STATUS_LIMIT)
  39. end
  40. end