2017-08-12 18:44:41 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::UpdateDistributionWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
sidekiq_options queue: 'push'
|
|
|
|
|
|
|
|
def perform(account_id)
|
|
|
|
@account = Account.find(account_id)
|
|
|
|
|
|
|
|
ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
|
2018-07-12 20:16:06 -04:00
|
|
|
[signed_payload, @account.id, inbox_url]
|
|
|
|
end
|
|
|
|
|
|
|
|
ActivityPub::DeliveryWorker.push_bulk(Relay.enabled.pluck(:inbox_url)) do |inbox_url|
|
|
|
|
[signed_payload, @account.id, inbox_url]
|
2017-08-12 18:44:41 -04:00
|
|
|
end
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def inboxes
|
|
|
|
@inboxes ||= @account.followers.inboxes
|
|
|
|
end
|
|
|
|
|
2018-07-12 20:16:06 -04:00
|
|
|
def signed_payload
|
|
|
|
@signed_payload ||= Oj.dump(ActivityPub::LinkedDataSignature.new(payload).sign!(@account))
|
|
|
|
end
|
|
|
|
|
2017-08-12 18:44:41 -04:00
|
|
|
def payload
|
|
|
|
@payload ||= ActiveModelSerializers::SerializableResource.new(
|
|
|
|
@account,
|
|
|
|
serializer: ActivityPub::UpdateSerializer,
|
|
|
|
adapter: ActivityPub::Adapter
|
|
|
|
).to_json
|
|
|
|
end
|
|
|
|
end
|