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.

57 lines
1.9 KiB

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