Add conversation-based forwarding for limited visibility statuses through bearcaps
This commit is contained in:
parent
52157fdcba
commit
7cd4ed7d42
26 changed files with 430 additions and 78 deletions
|
@ -12,8 +12,10 @@ class ActivityPub::DistributionWorker
|
|||
|
||||
return if skip_distribution?
|
||||
|
||||
ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
|
||||
[payload, @account.id, inbox_url]
|
||||
if delegate_distribution?
|
||||
deliver_to_parent!
|
||||
else
|
||||
deliver_to_inboxes!
|
||||
end
|
||||
|
||||
relay! if relayable?
|
||||
|
@ -24,22 +26,44 @@ class ActivityPub::DistributionWorker
|
|||
private
|
||||
|
||||
def skip_distribution?
|
||||
@status.direct_visibility? || @status.limited_visibility?
|
||||
@status.direct_visibility?
|
||||
end
|
||||
|
||||
def delegate_distribution?
|
||||
@status.limited_visibility? && @status.reply? && !@status.conversation.local?
|
||||
end
|
||||
|
||||
def relayable?
|
||||
@status.public_visibility?
|
||||
end
|
||||
|
||||
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]
|
||||
end
|
||||
end
|
||||
|
||||
def inboxes
|
||||
# Deliver the status to all followers.
|
||||
# If the status is a reply to another local status, also forward it to that
|
||||
# status' authors' followers.
|
||||
@inboxes ||= if @status.reply? && @status.thread.account.local? && @status.distributable?
|
||||
@account.followers.or(@status.thread.account.followers).inboxes
|
||||
else
|
||||
@account.followers.inboxes
|
||||
end
|
||||
# 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.reply? && @status.thread.account.local? && @status.distributable?
|
||||
@account.followers.or(@status.thread.account.followers).inboxes
|
||||
else
|
||||
@account.followers.inboxes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def payload
|
||||
|
|
27
app/workers/activitypub/forward_distribution_worker.rb
Normal file
27
app/workers/activitypub/forward_distribution_worker.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::ForwardDistributionWorker < ActivityPub::DistributionWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
sidekiq_options queue: 'push'
|
||||
|
||||
def perform(conversation_id, json)
|
||||
conversation = Conversation.find(conversation_id)
|
||||
|
||||
@status = conversation.parent_status
|
||||
@account = conversation.parent_account
|
||||
@json = json
|
||||
|
||||
return if @status.nil? || @account.nil?
|
||||
|
||||
deliver_to_inboxes!
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def payload
|
||||
@json
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue