logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

reply_distribution_worker.rb (977B)


  1. # frozen_string_literal: true
  2. class ActivityPub::ReplyDistributionWorker
  3. include Sidekiq::Worker
  4. sidekiq_options queue: 'push'
  5. def perform(status_id)
  6. @status = Status.find(status_id)
  7. @account = @status.thread&.account
  8. return if @account.nil? || skip_distribution?
  9. ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
  10. [signed_payload, @status.account_id, inbox_url]
  11. end
  12. rescue ActiveRecord::RecordNotFound
  13. true
  14. end
  15. private
  16. def skip_distribution?
  17. @status.private_visibility? || @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!(@status.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