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.

48 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::RawDistributionWorker
  3. include Sidekiq::Worker
  4. include Payloadable
  5. sidekiq_options queue: 'push'
  6. # Base worker for when you want to queue up a bunch of deliveries of
  7. # some payload. In this case, we have already generated JSON and
  8. # we are going to distribute it to the account's followers minus
  9. # the explicitly provided inboxes
  10. def perform(json, source_account_id, exclude_inboxes = [])
  11. @account = Account.find(source_account_id)
  12. @json = json
  13. @exclude_inboxes = exclude_inboxes
  14. distribute!
  15. rescue ActiveRecord::RecordNotFound
  16. true
  17. end
  18. protected
  19. def distribute!
  20. return if inboxes.empty?
  21. ActivityPub::DeliveryWorker.push_bulk(inboxes, limit: 1_000) do |inbox_url|
  22. [payload, source_account_id, inbox_url, options]
  23. end
  24. end
  25. def payload
  26. @json
  27. end
  28. def source_account_id
  29. @account.id
  30. end
  31. def inboxes
  32. @inboxes ||= @account.followers.inboxes - @exclude_inboxes
  33. end
  34. def options
  35. {}
  36. end
  37. end