You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.4 KiB

  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. @status.account.followers.inboxes
  53. end
  54. def relay_inboxes
  55. if @status.public_visibility?
  56. Relay.enabled.pluck(:inbox_url)
  57. else
  58. []
  59. end
  60. end
  61. end