Handle Add activity to featuredCollections (#38167)

This commit is contained in:
David Roetzel 2026-03-12 11:14:22 +01:00 committed by GitHub
parent 7f9df6d02d
commit 94aa5d7c9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 50 additions and 0 deletions

View File

@ -12,6 +12,10 @@ class ActivityPub::Activity::Add < ActivityPub::Activity
else
add_featured
end
when @account.collections_url
return unless Mastodon::Feature.collections_federation_enabled?
add_collection
else
@collection = @account.collections.find_by(uri: @json['target'])
add_collection_item if @collection && Mastodon::Feature.collections_federation_enabled?
@ -34,6 +38,10 @@ class ActivityPub::Activity::Add < ActivityPub::Activity
FeaturedTag.create!(account: @account, name: name) if name.present?
end
def add_collection
ActivityPub::ProcessFeaturedCollectionService.new.call(@account, @object)
end
def add_collection_item
ActivityPub::ProcessFeaturedItemService.new.call(@collection, @object)
end

View File

@ -80,6 +80,48 @@ RSpec.describe ActivityPub::Activity::Add do
end
end
context 'when the target is the `featuredCollections` collection', feature: :collections_federation do
subject { described_class.new(activity_json, account) }
let(:account) { Fabricate(:remote_account, collections_url: 'https://example.com/actor/1/featured_collections') }
let(:featured_collection_json) do
{
'@context' => 'https://www.w3.org/ns/activitystreams',
'id' => 'https://other.example.com/featured_item/1',
'type' => 'FeaturedCollection',
'attributedTo' => account.uri,
'name' => 'Cool people',
'summary' => 'People you should follow.',
'totalItems' => 0,
'sensitive' => false,
'discoverable' => true,
'published' => '2026-03-09T15:19:25Z',
}
end
let(:activity_json) do
{
'@context' => 'https://www.w3.org/ns/activitystreams',
'type' => 'Add',
'actor' => account.uri,
'target' => 'https://example.com/actor/1/featured_collections',
'object' => featured_collection_json,
}
end
let(:stubbed_service) do
instance_double(ActivityPub::ProcessFeaturedCollectionService, call: true)
end
before do
allow(ActivityPub::ProcessFeaturedCollectionService).to receive(:new).and_return(stubbed_service)
end
it 'calls the service' do
subject.perform
expect(stubbed_service).to have_received(:call).with(account, featured_collection_json)
end
end
context 'when the target is a collection', feature: :collections_federation do
subject { described_class.new(activity_json, collection.account) }