commit: 02ba03d6dba9e5633013e50366daabe573759168
parent: 3bee0996c509f4b416096094061edbc9c10f5632
Author: Eugen Rochko <eugen@zeonfederated.com>
Date: Thu, 4 Jan 2018 14:40:49 +0100
Send one Delete of Actor in ActivityPub when account is suspended (#6172)
Diffstat:
3 files changed, 35 insertions(+), 37 deletions(-)
diff --git a/app/serializers/activitypub/delete_actor_serializer.rb b/app/serializers/activitypub/delete_actor_serializer.rb
@@ -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
diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb
@@ -17,9 +17,7 @@ class BatchedRemoveStatusService < BaseService
@stream_entry_batches = []
@salmon_batches = []
- @activity_json_batches = []
@json_payloads = statuses.map { |s| [s.id, Oj.dump(event: :delete, payload: s.id.to_s)] }.to_h
- @activity_json = {}
@activity_xml = {}
# Ensure that rendered XML reflects destroyed state
@@ -32,10 +30,7 @@ class BatchedRemoveStatusService < BaseService
unpush_from_home_timelines(account, account_statuses)
unpush_from_list_timelines(account, account_statuses)
- if account.local?
- batch_stream_entries(account, account_statuses)
- batch_activity_json(account, account_statuses)
- end
+ batch_stream_entries(account, account_statuses) if account.local?
end
# Cannot be batched
@@ -46,7 +41,6 @@ class BatchedRemoveStatusService < BaseService
Pubsubhubbub::RawDistributionWorker.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
@@ -57,22 +51,6 @@ 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(account, statuses)
recipients = account.followers.local.to_a
@@ -123,23 +101,9 @@ class BatchedRemoveStatusService < BaseService
Redis.current
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)
return @activity_xml[stream_entry.id] if @activity_xml.key?(stream_entry.id)
@activity_xml[stream_entry.id] = stream_entry_to_xml(stream_entry)
end
-
- def sign_json(status, json)
- Oj.dump(ActivityPub::LinkedDataSignature.new(json).sign!(status.account))
- end
end
diff --git a/app/services/suspend_account_service.rb b/app/services/suspend_account_service.rb
@@ -22,6 +22,8 @@ class SuspendAccountService < BaseService
end
def purge_content!
+ ActivityPub::RawDistributionWorker.perform_async(delete_actor_json, @account.id) if @account.local?
+
@account.statuses.reorder(nil).find_in_batches do |statuses|
BatchedRemoveStatusService.new.call(statuses)
end
@@ -54,4 +56,14 @@ class SuspendAccountService < BaseService
def destroy_all(association)
association.in_batches.destroy_all
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