闭社主体 forked from https://github.com/tootsuite/mastodon
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.

54 lines
1.9 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 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. return if status.account.silenced? || !status.public_visibility? || status.reblog?
  9. deliver_to_hashtags(status)
  10. return if status.reply? && status.in_reply_to_account_id != status.account_id
  11. deliver_to_public(status)
  12. end
  13. private
  14. def deliver_to_self(status)
  15. Rails.logger.debug "Delivering status #{status.id} to author"
  16. FeedManager.instance.push(:home, status.account, status)
  17. end
  18. def deliver_to_followers(status)
  19. Rails.logger.debug "Delivering status #{status.id} to followers"
  20. status.account.followers.where(domain: nil).joins(:user).where('users.current_sign_in_at > ?', 14.days.ago).find_each do |follower|
  21. next if FeedManager.instance.filter?(:home, status, follower)
  22. FeedManager.instance.push(:home, follower, status)
  23. end
  24. end
  25. def deliver_to_hashtags(status)
  26. Rails.logger.debug "Delivering status #{status.id} to hashtags"
  27. payload = FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status)
  28. status.tags.find_each do |tag|
  29. FeedManager.instance.broadcast("hashtag:#{tag.name}", event: 'update', payload: payload)
  30. FeedManager.instance.broadcast("hashtag:#{tag.name}:local", event: 'update', payload: payload) if status.account.local?
  31. end
  32. end
  33. def deliver_to_public(status)
  34. Rails.logger.debug "Delivering status #{status.id} to public timeline"
  35. payload = FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status)
  36. FeedManager.instance.broadcast(:public, event: 'update', payload: payload)
  37. FeedManager.instance.broadcast('public:local', event: 'update', payload: payload) if status.account.local?
  38. end
  39. end