Handle Add activity to featuredCollections (#38167)
This commit is contained in:
@@ -12,6 +12,10 @@ class ActivityPub::Activity::Add < ActivityPub::Activity
|
|||||||
else
|
else
|
||||||
add_featured
|
add_featured
|
||||||
end
|
end
|
||||||
|
when @account.collections_url
|
||||||
|
return unless Mastodon::Feature.collections_federation_enabled?
|
||||||
|
|
||||||
|
add_collection
|
||||||
else
|
else
|
||||||
@collection = @account.collections.find_by(uri: @json['target'])
|
@collection = @account.collections.find_by(uri: @json['target'])
|
||||||
add_collection_item if @collection && Mastodon::Feature.collections_federation_enabled?
|
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?
|
FeaturedTag.create!(account: @account, name: name) if name.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_collection
|
||||||
|
ActivityPub::ProcessFeaturedCollectionService.new.call(@account, @object)
|
||||||
|
end
|
||||||
|
|
||||||
def add_collection_item
|
def add_collection_item
|
||||||
ActivityPub::ProcessFeaturedItemService.new.call(@collection, @object)
|
ActivityPub::ProcessFeaturedItemService.new.call(@collection, @object)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -80,6 +80,48 @@ RSpec.describe ActivityPub::Activity::Add do
|
|||||||
end
|
end
|
||||||
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
|
context 'when the target is a collection', feature: :collections_federation do
|
||||||
subject { described_class.new(activity_json, collection.account) }
|
subject { described_class.new(activity_json, collection.account) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user