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.

42 lines
902 B

  1. # frozen_string_literal: true
  2. class ActivityPub::DistributionWorker
  3. include Sidekiq::Worker
  4. sidekiq_options queue: 'push'
  5. def perform(status_id)
  6. @status = Status.find(status_id)
  7. @account = @status.account
  8. return if skip_distribution?
  9. ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
  10. [signed_payload, @account.id, inbox_url]
  11. end
  12. rescue ActiveRecord::RecordNotFound
  13. true
  14. end
  15. private
  16. def skip_distribution?
  17. @status.direct_visibility?
  18. end
  19. def inboxes
  20. @inboxes ||= @account.followers.inboxes
  21. end
  22. def signed_payload
  23. @signed_payload ||= Oj.dump(ActivityPub::LinkedDataSignature.new(payload).sign!(@account))
  24. end
  25. def payload
  26. @payload ||= ActiveModelSerializers::SerializableResource.new(
  27. @status,
  28. serializer: ActivityPub::ActivitySerializer,
  29. adapter: ActivityPub::Adapter
  30. ).as_json
  31. end
  32. end