2017-08-26 16:52:53 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::RawDistributionWorker
|
|
|
|
include Sidekiq::Worker
|
2022-01-19 21:37:27 +00:00
|
|
|
include Payloadable
|
2017-08-26 16:52:53 +00:00
|
|
|
|
|
|
|
sidekiq_options queue: 'push'
|
|
|
|
|
2022-01-19 21:37:27 +00:00
|
|
|
# Base worker for when you want to queue up a bunch of deliveries of
|
|
|
|
# some payload. In this case, we have already generated JSON and
|
|
|
|
# we are going to distribute it to the account's followers minus
|
|
|
|
# the explicitly provided inboxes
|
2017-11-30 02:50:05 +00:00
|
|
|
def perform(json, source_account_id, exclude_inboxes = [])
|
2022-01-19 21:37:27 +00:00
|
|
|
@account = Account.find(source_account_id)
|
|
|
|
@json = json
|
|
|
|
@exclude_inboxes = exclude_inboxes
|
2017-08-26 16:52:53 +00:00
|
|
|
|
2022-01-19 21:37:27 +00:00
|
|
|
distribute!
|
2017-08-26 16:52:53 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2022-01-19 21:37:27 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def distribute!
|
|
|
|
return if inboxes.empty?
|
|
|
|
|
2023-03-15 02:45:15 +00:00
|
|
|
ActivityPub::DeliveryWorker.push_bulk(inboxes, limit: 1_000) do |inbox_url|
|
2022-01-19 21:37:27 +00:00
|
|
|
[payload, source_account_id, inbox_url, options]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def payload
|
|
|
|
@json
|
|
|
|
end
|
|
|
|
|
|
|
|
def source_account_id
|
|
|
|
@account.id
|
|
|
|
end
|
2017-08-26 16:52:53 +00:00
|
|
|
|
|
|
|
def inboxes
|
2022-01-19 21:37:27 +00:00
|
|
|
@inboxes ||= @account.followers.inboxes - @exclude_inboxes
|
|
|
|
end
|
|
|
|
|
|
|
|
def options
|
2022-01-19 22:05:59 +00:00
|
|
|
{}
|
2017-08-26 16:52:53 +00:00
|
|
|
end
|
|
|
|
end
|