From e4e584a99e63ad479005c965ce45b7ad47563b3a Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Mon, 23 Mar 2026 16:57:02 +0100 Subject: [PATCH] Handle `Update` of a `FeaturedCollection` (#38337) --- app/lib/activitypub/activity/update.rb | 8 ++++ spec/lib/activitypub/activity/update_spec.rb | 40 ++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/app/lib/activitypub/activity/update.rb b/app/lib/activitypub/activity/update.rb index e22bea2c64..b40e8f381b 100644 --- a/app/lib/activitypub/activity/update.rb +++ b/app/lib/activitypub/activity/update.rb @@ -13,6 +13,8 @@ class ActivityPub::Activity::Update < ActivityPub::Activity update_account elsif supported_object_type? || converted_object_type? update_status + elsif equals_or_includes_any?(@object['type'], ['FeaturedCollection']) && Mastodon::Feature.collections_federation_enabled? + update_collection end end @@ -41,6 +43,12 @@ class ActivityPub::Activity::Update < ActivityPub::Activity ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id]) end + def update_collection + return reject_payload! if non_matching_uri_hosts?(@account.uri, object_uri) + + ActivityPub::ProcessFeaturedCollectionService.new.call(@account, @object) + end + def object_too_old? @object['published'].present? && @object['published'].to_datetime < OBJECT_AGE_THRESHOLD.ago rescue Date::Error diff --git a/spec/lib/activitypub/activity/update_spec.rb b/spec/lib/activitypub/activity/update_spec.rb index d905f68d8f..ba69c4afc2 100644 --- a/spec/lib/activitypub/activity/update_spec.rb +++ b/spec/lib/activitypub/activity/update_spec.rb @@ -256,5 +256,45 @@ RSpec.describe ActivityPub::Activity::Update do end end end + + context 'with a `FeaturedCollection` object', feature: :collections_federation do + let(:collection) { Fabricate(:remote_collection, account: sender, name: 'old name', discoverable: false) } + let(:featured_collection_json) do + { + '@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => collection.uri, + 'type' => 'FeaturedCollection', + 'attributedTo' => sender.uri, + 'name' => 'Cool people', + 'summary' => 'People you should follow.', + 'totalItems' => 0, + 'sensitive' => false, + 'discoverable' => true, + 'published' => '2026-03-09T15:19:25Z', + 'updated' => Time.zone.now.iso8601, + } + end + let(:json) do + { + '@context' => 'https://www.w3.org/ns/activitystreams', + 'type' => 'Update', + 'actor' => sender.uri, + '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 'updates the collection' do + subject.perform + + expect(stubbed_service).to have_received(:call).with(sender, featured_collection_json) + end + end end end