ActivityPub delivery (#4566)
* Deliver ActivityPub Like * Deliver ActivityPub Undo-Like * Deliver ActivityPub Create/Announce activities * Deliver ActivityPub creates from mentions * Deliver ActivityPub Block/Undo-Block * Deliver ActivityPub Accept/Reject-Follow * Deliver ActivityPub Undo-Follow * Deliver ActivityPub Follow * Deliver ActivityPub Delete activities Incidentally fix #889 * Adjust BatchedRemoveStatusService for ActivityPub * Add tests for ActivityPub workers * Add tests for FollowService * Add tests for FavouriteService, UnfollowService and PostStatusService * Add tests for ReblogService, BlockService, UnblockService, ProcessMentionsService * Add tests for AuthorizeFollowService, RejectFollowService, RemoveStatusService * Add tests for BatchedRemoveStatusService * Deliver updates to a local account to ActivityPub followers * Minor adjustments
This commit is contained in:
parent
ccdd5a9576
commit
b7370ac8ba
41 changed files with 786 additions and 114 deletions
|
@ -15,9 +15,11 @@ class BatchedRemoveStatusService < BaseService
|
|||
@mentions = statuses.map { |s| [s.id, s.mentions.includes(:account).to_a] }.to_h
|
||||
@tags = statuses.map { |s| [s.id, s.tags.pluck(:name)] }.to_h
|
||||
|
||||
@stream_entry_batches = []
|
||||
@salmon_batches = []
|
||||
@json_payloads = statuses.map { |s| [s.id, Oj.dump(event: :delete, payload: s.id)] }.to_h
|
||||
@stream_entry_batches = []
|
||||
@salmon_batches = []
|
||||
@activity_json_batches = []
|
||||
@json_payloads = statuses.map { |s| [s.id, Oj.dump(event: :delete, payload: s.id)] }.to_h
|
||||
@activity_json = {}
|
||||
|
||||
# Ensure that rendered XML reflects destroyed state
|
||||
Status.where(id: statuses.map(&:id)).in_batches.destroy_all
|
||||
|
@ -27,7 +29,11 @@ class BatchedRemoveStatusService < BaseService
|
|||
account = account_statuses.first.account
|
||||
|
||||
unpush_from_home_timelines(account_statuses)
|
||||
batch_stream_entries(account_statuses) if account.local?
|
||||
|
||||
if account.local?
|
||||
batch_stream_entries(account_statuses)
|
||||
batch_activity_json(account, account_statuses)
|
||||
end
|
||||
end
|
||||
|
||||
# Cannot be batched
|
||||
|
@ -38,6 +44,7 @@ class BatchedRemoveStatusService < BaseService
|
|||
|
||||
Pubsubhubbub::DistributionWorker.push_bulk(@stream_entry_batches) { |batch| batch }
|
||||
NotificationWorker.push_bulk(@salmon_batches) { |batch| batch }
|
||||
ActivityPub::DeliveryWorker.push_bulk(@activity_json_batches) { |batch| batch }
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -50,6 +57,22 @@ class BatchedRemoveStatusService < BaseService
|
|||
end
|
||||
end
|
||||
|
||||
def batch_activity_json(account, statuses)
|
||||
account.followers.inboxes.each do |inbox_url|
|
||||
statuses.each do |status|
|
||||
@activity_json_batches << [build_json(status), account.id, inbox_url]
|
||||
end
|
||||
end
|
||||
|
||||
statuses.each do |status|
|
||||
other_recipients = (status.mentions + status.reblogs).map(&:account).reject(&:local?).select(&:activitypub?).uniq(&:id)
|
||||
|
||||
other_recipients.each do |target_account|
|
||||
@activity_json_batches << [build_json(status), account.id, target_account.inbox_url]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def unpush_from_home_timelines(statuses)
|
||||
account = statuses.first.account
|
||||
recipients = account.followers.local.pluck(:id)
|
||||
|
@ -79,7 +102,7 @@ class BatchedRemoveStatusService < BaseService
|
|||
return if @mentions[status.id].empty?
|
||||
|
||||
payload = stream_entry_to_xml(status.stream_entry.reload)
|
||||
recipients = @mentions[status.id].map(&:account).reject(&:local?).uniq(&:domain).map(&:id)
|
||||
recipients = @mentions[status.id].map(&:account).reject(&:local?).select(&:ostatus?).uniq(&:domain).map(&:id)
|
||||
|
||||
recipients.each do |recipient_id|
|
||||
@salmon_batches << [payload, status.account_id, recipient_id]
|
||||
|
@ -111,4 +134,14 @@ class BatchedRemoveStatusService < BaseService
|
|||
def redis
|
||||
Redis.current
|
||||
end
|
||||
|
||||
def build_json(status)
|
||||
return @activity_json[status.id] if @activity_json.key?(status.id)
|
||||
|
||||
@activity_json[status.id] = ActiveModelSerializers::SerializableResource.new(
|
||||
status,
|
||||
serializer: ActivityPub::DeleteSerializer,
|
||||
adapter: ActivityPub::Adapter
|
||||
).to_json
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue