status_reach_finder.rb 934 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. class StatusReachFinder
  3. def initialize(status)
  4. @status = status
  5. end
  6. def inboxes
  7. Account.where(id: reached_account_ids).inboxes
  8. end
  9. private
  10. def reached_account_ids
  11. [
  12. replied_to_account_id,
  13. reblog_of_account_id,
  14. mentioned_account_ids,
  15. reblogs_account_ids,
  16. favourites_account_ids,
  17. replies_account_ids,
  18. ].tap do |arr|
  19. arr.flatten!
  20. arr.compact!
  21. arr.uniq!
  22. end
  23. end
  24. def replied_to_account_id
  25. @status.in_reply_to_account_id
  26. end
  27. def reblog_of_account_id
  28. @status.reblog.account_id if @status.reblog?
  29. end
  30. def mentioned_account_ids
  31. @status.mentions.pluck(:account_id)
  32. end
  33. def reblogs_account_ids
  34. @status.reblogs.pluck(:account_id)
  35. end
  36. def favourites_account_ids
  37. @status.favourites.pluck(:account_id)
  38. end
  39. def replies_account_ids
  40. @status.replies.pluck(:account_id)
  41. end
  42. end