forked from cybrespace/mastodon
Send one Delete of Actor in ActivityPub when account is suspended (#6172)
This commit is contained in:
parent
3bee0996c5
commit
02ba03d6db
|
@ -0,0 +1,22 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ActivityPub::DeleteActorSerializer < ActiveModel::Serializer
|
||||||
|
attributes :id, :type, :actor
|
||||||
|
attribute :virtual_object, key: :object
|
||||||
|
|
||||||
|
def id
|
||||||
|
[ActivityPub::TagManager.instance.uri_for(object), '#delete'].join
|
||||||
|
end
|
||||||
|
|
||||||
|
def type
|
||||||
|
'Delete'
|
||||||
|
end
|
||||||
|
|
||||||
|
def actor
|
||||||
|
ActivityPub::TagManager.instance.uri_for(object)
|
||||||
|
end
|
||||||
|
|
||||||
|
def virtual_object
|
||||||
|
actor
|
||||||
|
end
|
||||||
|
end
|
|
@ -17,9 +17,7 @@ class BatchedRemoveStatusService < BaseService
|
||||||
|
|
||||||
@stream_entry_batches = []
|
@stream_entry_batches = []
|
||||||
@salmon_batches = []
|
@salmon_batches = []
|
||||||
@activity_json_batches = []
|
|
||||||
@json_payloads = statuses.map { |s| [s.id, Oj.dump(event: :delete, payload: s.id.to_s)] }.to_h
|
@json_payloads = statuses.map { |s| [s.id, Oj.dump(event: :delete, payload: s.id.to_s)] }.to_h
|
||||||
@activity_json = {}
|
|
||||||
@activity_xml = {}
|
@activity_xml = {}
|
||||||
|
|
||||||
# Ensure that rendered XML reflects destroyed state
|
# Ensure that rendered XML reflects destroyed state
|
||||||
|
@ -32,10 +30,7 @@ class BatchedRemoveStatusService < BaseService
|
||||||
unpush_from_home_timelines(account, account_statuses)
|
unpush_from_home_timelines(account, account_statuses)
|
||||||
unpush_from_list_timelines(account, account_statuses)
|
unpush_from_list_timelines(account, account_statuses)
|
||||||
|
|
||||||
if account.local?
|
batch_stream_entries(account, account_statuses) if account.local?
|
||||||
batch_stream_entries(account, account_statuses)
|
|
||||||
batch_activity_json(account, account_statuses)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Cannot be batched
|
# Cannot be batched
|
||||||
|
@ -46,7 +41,6 @@ class BatchedRemoveStatusService < BaseService
|
||||||
|
|
||||||
Pubsubhubbub::RawDistributionWorker.push_bulk(@stream_entry_batches) { |batch| batch }
|
Pubsubhubbub::RawDistributionWorker.push_bulk(@stream_entry_batches) { |batch| batch }
|
||||||
NotificationWorker.push_bulk(@salmon_batches) { |batch| batch }
|
NotificationWorker.push_bulk(@salmon_batches) { |batch| batch }
|
||||||
ActivityPub::DeliveryWorker.push_bulk(@activity_json_batches) { |batch| batch }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -57,22 +51,6 @@ class BatchedRemoveStatusService < BaseService
|
||||||
end
|
end
|
||||||
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(account, statuses)
|
def unpush_from_home_timelines(account, statuses)
|
||||||
recipients = account.followers.local.to_a
|
recipients = account.followers.local.to_a
|
||||||
|
|
||||||
|
@ -123,23 +101,9 @@ class BatchedRemoveStatusService < BaseService
|
||||||
Redis.current
|
Redis.current
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_json(status)
|
|
||||||
return @activity_json[status.id] if @activity_json.key?(status.id)
|
|
||||||
|
|
||||||
@activity_json[status.id] = sign_json(status, ActiveModelSerializers::SerializableResource.new(
|
|
||||||
status,
|
|
||||||
serializer: status.reblog? ? ActivityPub::UndoAnnounceSerializer : ActivityPub::DeleteSerializer,
|
|
||||||
adapter: ActivityPub::Adapter
|
|
||||||
).as_json)
|
|
||||||
end
|
|
||||||
|
|
||||||
def build_xml(stream_entry)
|
def build_xml(stream_entry)
|
||||||
return @activity_xml[stream_entry.id] if @activity_xml.key?(stream_entry.id)
|
return @activity_xml[stream_entry.id] if @activity_xml.key?(stream_entry.id)
|
||||||
|
|
||||||
@activity_xml[stream_entry.id] = stream_entry_to_xml(stream_entry)
|
@activity_xml[stream_entry.id] = stream_entry_to_xml(stream_entry)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sign_json(status, json)
|
|
||||||
Oj.dump(ActivityPub::LinkedDataSignature.new(json).sign!(status.account))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,8 @@ class SuspendAccountService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def purge_content!
|
def purge_content!
|
||||||
|
ActivityPub::RawDistributionWorker.perform_async(delete_actor_json, @account.id) if @account.local?
|
||||||
|
|
||||||
@account.statuses.reorder(nil).find_in_batches do |statuses|
|
@account.statuses.reorder(nil).find_in_batches do |statuses|
|
||||||
BatchedRemoveStatusService.new.call(statuses)
|
BatchedRemoveStatusService.new.call(statuses)
|
||||||
end
|
end
|
||||||
|
@ -54,4 +56,14 @@ class SuspendAccountService < BaseService
|
||||||
def destroy_all(association)
|
def destroy_all(association)
|
||||||
association.in_batches.destroy_all
|
association.in_batches.destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete_actor_json
|
||||||
|
payload = ActiveModelSerializers::SerializableResource.new(
|
||||||
|
@account,
|
||||||
|
serializer: ActivityPub::DeleteActorSerializer,
|
||||||
|
adapter: ActivityPub::Adapter
|
||||||
|
).as_json
|
||||||
|
|
||||||
|
Oj.dump(ActivityPub::LinkedDataSignature.new(payload).sign!(@account))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue