The code powering m.abunchtell.com https://m.abunchtell.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

55 行
1.3 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::DistributionWorker
  3. include Sidekiq::Worker
  4. include Payloadable
  5. sidekiq_options queue: 'push'
  6. def perform(status_id)
  7. @status = Status.find(status_id)
  8. @account = @status.account
  9. return if skip_distribution?
  10. ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
  11. [payload, @account.id, inbox_url]
  12. end
  13. relay! if relayable?
  14. rescue ActiveRecord::RecordNotFound
  15. true
  16. end
  17. private
  18. def skip_distribution?
  19. @status.direct_visibility? || @status.limited_visibility?
  20. end
  21. def relayable?
  22. @status.public_visibility?
  23. end
  24. def inboxes
  25. # Deliver the status to all followers.
  26. # If the status is a reply to another local status, also forward it to that
  27. # status' authors' followers.
  28. @inboxes ||= if @status.reply? && @status.thread.account.local? && @status.distributable?
  29. @account.followers.or(@status.thread.account.followers).inboxes
  30. else
  31. @account.followers.inboxes
  32. end
  33. end
  34. def payload
  35. @payload ||= Oj.dump(serialize_payload(@status, ActivityPub::ActivitySerializer, signer: @account))
  36. end
  37. def relay!
  38. ActivityPub::DeliveryWorker.push_bulk(Relay.enabled.pluck(:inbox_url)) do |inbox_url|
  39. [payload, @account.id, inbox_url]
  40. end
  41. end
  42. end