闭社主体 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.

30 lines
891 B

  1. # frozen_string_literal: true
  2. class Pubsubhubbub::DistributionWorker
  3. include Sidekiq::Worker
  4. sidekiq_options queue: 'push'
  5. def perform(stream_entry_id)
  6. stream_entry = StreamEntry.find(stream_entry_id)
  7. return if stream_entry.status&.direct_visibility?
  8. @account = stream_entry.account
  9. @payload = AtomSerializer.render(AtomSerializer.new.feed(@account, [stream_entry]))
  10. @domains = @account.followers_domains
  11. Subscription.where(account: @account).active.select('id, callback_url').find_each do |subscription|
  12. next if stream_entry.hidden? && !allowed_to_receive?(subscription.callback_url)
  13. Pubsubhubbub::DeliveryWorker.perform_async(subscription.id, @payload)
  14. end
  15. rescue ActiveRecord::RecordNotFound
  16. true
  17. end
  18. private
  19. def allowed_to_receive?(callback_url)
  20. @domains.include?(Addressable::URI.parse(callback_url).host)
  21. end
  22. end