2017-08-12 22:44:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub::DistributionWorker
|
|
|
|
include Sidekiq::Worker
|
2019-06-04 21:11:18 +00:00
|
|
|
include Payloadable
|
2017-08-12 22:44:41 +00:00
|
|
|
|
|
|
|
sidekiq_options queue: 'push'
|
|
|
|
|
|
|
|
def perform(status_id)
|
|
|
|
@status = Status.find(status_id)
|
|
|
|
@account = @status.account
|
|
|
|
|
|
|
|
return if skip_distribution?
|
|
|
|
|
2020-09-05 07:33:17 +00:00
|
|
|
if delegate_distribution?
|
|
|
|
deliver_to_parent!
|
|
|
|
else
|
|
|
|
deliver_to_inboxes!
|
2017-08-12 22:44:41 +00:00
|
|
|
end
|
2018-07-13 00:16:06 +00:00
|
|
|
|
|
|
|
relay! if relayable?
|
2017-08-12 22:44:41 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def skip_distribution?
|
2020-09-05 07:33:17 +00:00
|
|
|
@status.direct_visibility?
|
|
|
|
end
|
|
|
|
|
|
|
|
def delegate_distribution?
|
|
|
|
@status.limited_visibility? && @status.reply? && !@status.conversation.local?
|
2017-08-12 22:44:41 +00:00
|
|
|
end
|
|
|
|
|
2018-07-13 00:16:06 +00:00
|
|
|
def relayable?
|
|
|
|
@status.public_visibility?
|
|
|
|
end
|
|
|
|
|
2020-09-05 07:33:17 +00:00
|
|
|
def deliver_to_parent!
|
|
|
|
return if @status.conversation.inbox_url.blank?
|
|
|
|
|
|
|
|
ActivityPub::DeliveryWorker.perform_async(payload, @account.id, @status.conversation.inbox_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def deliver_to_inboxes!
|
|
|
|
ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
|
|
|
|
[payload, @account.id, inbox_url, { synchronize_followers: !@status.distributable? }]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-12 22:44:41 +00:00
|
|
|
def inboxes
|
2020-09-05 07:33:17 +00:00
|
|
|
# Deliver the status to all followers. If the status is a reply
|
|
|
|
# to another local status, also forward it to that status'
|
|
|
|
# authors' followers. If the status has limited visibility,
|
|
|
|
# deliver it to inboxes of people mentioned (no shared ones)
|
|
|
|
|
|
|
|
@inboxes ||= begin
|
|
|
|
if @status.limited_visibility?
|
|
|
|
DeliveryFailureTracker.without_unavailable(Account.remote.joins(:mentions).merge(@status.mentions).pluck(:inbox_url))
|
|
|
|
elsif @status.in_reply_to_local_account? && @status.distributable?
|
|
|
|
@account.delivery_followers.or(@status.thread.account.delivery_followers).inboxes
|
|
|
|
else
|
|
|
|
@account.delivery_followers.inboxes
|
|
|
|
end
|
|
|
|
end
|
2017-08-12 22:44:41 +00:00
|
|
|
end
|
|
|
|
|
2018-12-30 08:48:59 +00:00
|
|
|
def payload
|
2020-06-02 17:24:53 +00:00
|
|
|
@payload ||= Oj.dump(serialize_payload(ActivityPub::ActivityPresenter.from_status(@status), ActivityPub::ActivitySerializer, signer: @account))
|
2018-12-30 08:48:59 +00:00
|
|
|
end
|
|
|
|
|
2018-07-13 00:16:06 +00:00
|
|
|
def relay!
|
|
|
|
ActivityPub::DeliveryWorker.push_bulk(Relay.enabled.pluck(:inbox_url)) do |inbox_url|
|
2018-12-30 08:48:59 +00:00
|
|
|
[payload, @account.id, inbox_url]
|
2018-07-13 00:16:06 +00:00
|
|
|
end
|
|
|
|
end
|
2017-08-12 22:44:41 +00:00
|
|
|
end
|