diff --git a/app/lib/activitypub/activity/remove.rb b/app/lib/activitypub/activity/remove.rb index f5cbef6757..2cf411317e 100644 --- a/app/lib/activitypub/activity/remove.rb +++ b/app/lib/activitypub/activity/remove.rb @@ -12,6 +12,8 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity else remove_featured end + when @account.collections_url + remove_collection end end @@ -34,4 +36,10 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity featured_tag = FeaturedTag.by_name(name).find_by(account: @account) featured_tag&.destroy! end + + def remove_collection + collection = @account.collections.find_by(uri: value_or_id(@object)) + + collection&.destroy! + end end diff --git a/spec/lib/activitypub/activity/remove_spec.rb b/spec/lib/activitypub/activity/remove_spec.rb index 937b938e4f..e0563e5c4d 100644 --- a/spec/lib/activitypub/activity/remove_spec.rb +++ b/spec/lib/activitypub/activity/remove_spec.rb @@ -3,7 +3,11 @@ require 'rails_helper' RSpec.describe ActivityPub::Activity::Remove do - let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured') } + let(:sender) do + Fabricate(:remote_account, + featured_collection_url: 'https://example.com/featured', + collections_url: 'https://example.com/actor/1/featured_collections') + end describe '#perform' do subject { described_class.new(json, sender) } @@ -59,5 +63,29 @@ RSpec.describe ActivityPub::Activity::Remove do .to change { sender.featured_tags.exists?(tag: tag) }.to(false) end end + + context 'when removing a featured collection' do + let(:collection) { Fabricate(:remote_collection, account: sender) } + let(:json) do + { + '@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => 'foo', + 'type' => 'Remove', + 'actor' => ActivityPub::TagManager.instance.uri_for(sender), + 'object' => collection.uri, + 'target' => sender.collections_url, + } + end + + before do + Fabricate(:collection_item, collection:, uri: 'https://example.com/featured_items/1') + end + + it 'deletes the collection' do + expect { subject.perform } + .to change(sender.collections, :count).by(-1) + .and change(CollectionItem, :count).by(-1) + end + end end end