From 69b74d26cdb6466bbaacea182ce77907ebfab640 Mon Sep 17 00:00:00 2001 From: unarist Date: Sat, 14 Oct 2017 21:42:09 +0900 Subject: [PATCH] Use atomUri in Undo activity of Announce (#5376) This allows deletion of reblogs which delivered before with OStatus URI. --- app/lib/activitypub/activity/undo.rb | 3 ++- .../activitypub/activity_serializer.rb | 5 ++++ spec/lib/activitypub/activity/undo_spec.rb | 24 +++++++++++++++---- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/lib/activitypub/activity/undo.rb b/app/lib/activitypub/activity/undo.rb index 4b0905de2a..cbed417c4e 100644 --- a/app/lib/activitypub/activity/undo.rb +++ b/app/lib/activitypub/activity/undo.rb @@ -17,7 +17,8 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity private def undo_announce - status = Status.find_by(uri: object_uri, account: @account) + status = Status.find_by(uri: object_uri, account: @account) + status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present? if status.nil? delete_later!(object_uri) diff --git a/app/serializers/activitypub/activity_serializer.rb b/app/serializers/activitypub/activity_serializer.rb index df399211c3..50c4f6a049 100644 --- a/app/serializers/activitypub/activity_serializer.rb +++ b/app/serializers/activitypub/activity_serializer.rb @@ -5,6 +5,7 @@ class ActivityPub::ActivitySerializer < ActiveModel::Serializer has_one :proper, key: :object, serializer: ActivityPub::NoteSerializer, unless: :announce? attribute :proper_uri, key: :object, if: :announce? + attribute :atom_uri, if: :announce? def id ActivityPub::TagManager.instance.activity_uri_for(object) @@ -34,6 +35,10 @@ class ActivityPub::ActivitySerializer < ActiveModel::Serializer ActivityPub::TagManager.instance.uri_for(object.proper) end + def atom_uri + OStatus::TagManager.instance.uri_for(object) + end + def announce? object.reblog? end diff --git a/spec/lib/activitypub/activity/undo_spec.rb b/spec/lib/activitypub/activity/undo_spec.rb index 14c68efe5f..e01c5e03e7 100644 --- a/spec/lib/activitypub/activity/undo_spec.rb +++ b/spec/lib/activitypub/activity/undo_spec.rb @@ -25,16 +25,30 @@ RSpec.describe ActivityPub::Activity::Undo do type: 'Announce', actor: ActivityPub::TagManager.instance.uri_for(sender), object: ActivityPub::TagManager.instance.uri_for(status), + atomUri: 'barbar', } end - before do - Fabricate(:status, reblog: status, account: sender, uri: 'bar') + context do + before do + Fabricate(:status, reblog: status, account: sender, uri: 'bar') + end + + it 'deletes the reblog' do + subject.perform + expect(sender.reblogged?(status)).to be false + end end - it 'deletes the reblog' do - subject.perform - expect(sender.reblogged?(status)).to be false + context 'with atomUri' do + before do + Fabricate(:status, reblog: status, account: sender, uri: 'barbar') + end + + it 'deletes the reblog by atomUri' do + subject.perform + expect(sender.reblogged?(status)).to be false + end end end