From 2a2698e4501094ca52b8b166c2c51fab26ce7427 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 26 Aug 2017 15:32:40 +0200 Subject: [PATCH] Add ActivityPub serializer for Undo of Announce (#4703) --- .../activitypub/undo_announce_serializer.rb | 19 +++++++++++++++++++ app/services/batched_remove_status_service.rb | 2 +- app/services/remove_status_service.rb | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/serializers/activitypub/undo_announce_serializer.rb diff --git a/app/serializers/activitypub/undo_announce_serializer.rb b/app/serializers/activitypub/undo_announce_serializer.rb new file mode 100644 index 00000000000..839847e22c0 --- /dev/null +++ b/app/serializers/activitypub/undo_announce_serializer.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class ActivityPub::UndoAnnounceSerializer < ActiveModel::Serializer + attributes :id, :type, :actor + + has_one :object, serializer: ActivityPub::ActivitySerializer + + def id + [ActivityPub::TagManager.instance.uri_for(object.account), '#announces/', object.id, '/undo'].join + end + + def type + 'Undo' + end + + def actor + ActivityPub::TagManager.instance.uri_for(object.account) + end +end diff --git a/app/services/batched_remove_status_service.rb b/app/services/batched_remove_status_service.rb index c90f4401dfb..e9e22298d59 100644 --- a/app/services/batched_remove_status_service.rb +++ b/app/services/batched_remove_status_service.rb @@ -140,7 +140,7 @@ class BatchedRemoveStatusService < BaseService @activity_json[status.id] = sign_json(status, ActiveModelSerializers::SerializableResource.new( status, - serializer: ActivityPub::DeleteSerializer, + serializer: status.reblog? ? ActivityPub::UndoAnnounceSerializer : ActivityPub::DeleteSerializer, adapter: ActivityPub::Adapter ).as_json) end diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb index 62eea677f60..434c9de8478 100644 --- a/app/services/remove_status_service.rb +++ b/app/services/remove_status_service.rb @@ -81,7 +81,7 @@ class RemoveStatusService < BaseService def activity_json @activity_json ||= ActiveModelSerializers::SerializableResource.new( @status, - serializer: ActivityPub::DeleteSerializer, + serializer: @status.reblog? ? ActivityPub::UndoAnnounceSerializer : ActivityPub::DeleteSerializer, adapter: ActivityPub::Adapter ).as_json end