status_reach_finder.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # frozen_string_literal: true
  2. class StatusReachFinder
  3. def initialize(status)
  4. @status = status
  5. end
  6. def inboxes
  7. (reached_account_inboxes + followers_inboxes + relay_inboxes).uniq
  8. end
  9. private
  10. def reached_account_inboxes
  11. # When the status is a reblog, there are no interactions with it
  12. # directly, we assume all interactions are with the original one
  13. if @status.reblog?
  14. []
  15. else
  16. Account.where(id: reached_account_ids).inboxes
  17. end
  18. end
  19. def reached_account_ids
  20. [
  21. replied_to_account_id,
  22. reblog_of_account_id,
  23. mentioned_account_ids,
  24. reblogs_account_ids,
  25. favourites_account_ids,
  26. replies_account_ids,
  27. ].tap do |arr|
  28. arr.flatten!
  29. arr.compact!
  30. arr.uniq!
  31. end
  32. end
  33. def replied_to_account_id
  34. @status.in_reply_to_account_id
  35. end
  36. def reblog_of_account_id
  37. @status.reblog.account_id if @status.reblog?
  38. end
  39. def mentioned_account_ids
  40. @status.mentions.pluck(:account_id)
  41. end
  42. def reblogs_account_ids
  43. @status.reblogs.pluck(:account_id)
  44. end
  45. def favourites_account_ids
  46. @status.favourites.pluck(:account_id)
  47. end
  48. def replies_account_ids
  49. @status.replies.pluck(:account_id)
  50. end
  51. def followers_inboxes
  52. if @status.in_reply_to_local_account? && @status.distributable?
  53. @status.account.followers.or(@status.thread.account.followers).inboxes
  54. else
  55. @status.account.followers.inboxes
  56. end
  57. end
  58. def relay_inboxes
  59. if @status.public_visibility?
  60. Relay.enabled.pluck(:inbox_url)
  61. else
  62. []
  63. end
  64. end
  65. end