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.

53 lines
1.6 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. class FanOutOnWriteService < BaseService
  2. # Push a status into home and mentions feeds
  3. # @param [Status] status
  4. def call(status)
  5. deliver_to_self(status) if status.account.local?
  6. deliver_to_followers(status)
  7. deliver_to_mentioned(status)
  8. return if status.account.silenced?
  9. deliver_to_hashtags(status)
  10. deliver_to_public(status)
  11. end
  12. private
  13. def deliver_to_self(status)
  14. Rails.logger.debug "Delivering status #{status.id} to author"
  15. FeedManager.instance.push(:home, status.account, status)
  16. end
  17. def deliver_to_followers(status)
  18. Rails.logger.debug "Delivering status #{status.id} to followers"
  19. status.account.followers.find_each do |follower|
  20. next if !follower.local? || FeedManager.instance.filter?(:home, status, follower)
  21. FeedManager.instance.push(:home, follower, status)
  22. end
  23. end
  24. def deliver_to_mentioned(status)
  25. Rails.logger.debug "Delivering status #{status.id} to mentioned accounts"
  26. status.mentions.includes(:account).each do |mention|
  27. mentioned_account = mention.account
  28. next if !mentioned_account.local? || FeedManager.instance.filter?(:mentions, status, mentioned_account)
  29. FeedManager.instance.push(:mentions, mentioned_account, status)
  30. end
  31. end
  32. def deliver_to_hashtags(status)
  33. Rails.logger.debug "Delivering status #{status.id} to hashtags"
  34. status.tags.find_each do |tag|
  35. FeedManager.instance.broadcast("hashtag:#{tag.name}", id: status.id)
  36. end
  37. end
  38. def deliver_to_public(status)
  39. Rails.logger.debug "Delivering status #{status.id} to public timeline"
  40. FeedManager.instance.broadcast(:public, id: status.id)
  41. end
  42. end