From 8552bd79b0faafcb653d9d2f50bb2f06d76eb663 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 28 Jul 2026 10:30:21 +0200 Subject: [PATCH] Remove processing of collections of activities (#39932) --- ...service.rb => process_activity_service.rb} | 21 +++---------------- app/workers/activitypub/processing_worker.rb | 2 +- ...ec.rb => process_activity_service_spec.rb} | 2 +- .../activitypub/processing_worker_spec.rb | 8 +++---- 4 files changed, 9 insertions(+), 24 deletions(-) rename app/services/activitypub/{process_collection_service.rb => process_activity_service.rb} (89%) rename spec/services/activitypub/{process_collection_service_spec.rb => process_activity_service_spec.rb} (99%) diff --git a/app/services/activitypub/process_collection_service.rb b/app/services/activitypub/process_activity_service.rb similarity index 89% rename from app/services/activitypub/process_collection_service.rb rename to app/services/activitypub/process_activity_service.rb index 315e0c26354..2e66044ff20 100644 --- a/app/services/activitypub/process_collection_service.rb +++ b/app/services/activitypub/process_activity_service.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ActivityPub::ProcessCollectionService < BaseService +class ActivityPub::ProcessActivityService < BaseService include JsonLdHelper include DomainControlHelper @@ -64,14 +64,8 @@ class ActivityPub::ProcessCollectionService < BaseService @json.delete('signature') unless safe_for_forwarding?(original_json, @json) end - case @json['type'] - when 'Collection', 'CollectionPage' - process_items @json['items'] - when 'OrderedCollection', 'OrderedCollectionPage' - process_items @json['orderedItems'] - else - process_items [@json] - end + activity = ActivityPub::Activity.factory(@json, @account, **@options) + activity&.perform rescue JSON::ParserError nil end @@ -90,15 +84,6 @@ class ActivityPub::ProcessCollectionService < BaseService %w(Delete Reject Undo Update).include?(@json['type']) end - def process_items(items) - items.reverse_each.filter_map { |item| process_item(item) } - end - - def process_item(item) - activity = ActivityPub::Activity.factory(item, @account, **@options) - activity&.perform - end - def actor_from_verified_ld_signature return unless @json['signature'].is_a?(Hash) return if domain_not_allowed?(@json['signature']['creator']) diff --git a/app/workers/activitypub/processing_worker.rb b/app/workers/activitypub/processing_worker.rb index 1bb94b7f264..5ccbaff44c3 100644 --- a/app/workers/activitypub/processing_worker.rb +++ b/app/workers/activitypub/processing_worker.rb @@ -13,7 +13,7 @@ class ActivityPub::ProcessingWorker return if actor.nil? - ActivityPub::ProcessCollectionService.new.call(body, actor, override_timestamps: true, delivered_to_account_id: delivered_to_account_id, delivery: true) + ActivityPub::ProcessActivityService.new.call(body, actor, override_timestamps: true, delivered_to_account_id: delivered_to_account_id, delivery: true) rescue ActiveRecord::RecordInvalid => e Rails.logger.debug { "Error processing incoming ActivityPub object: #{e}" } end diff --git a/spec/services/activitypub/process_collection_service_spec.rb b/spec/services/activitypub/process_activity_service_spec.rb similarity index 99% rename from spec/services/activitypub/process_collection_service_spec.rb rename to spec/services/activitypub/process_activity_service_spec.rb index 7e3e5a66957..8e547c4f474 100644 --- a/spec/services/activitypub/process_collection_service_spec.rb +++ b/spec/services/activitypub/process_activity_service_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe ActivityPub::ProcessCollectionService do +RSpec.describe ActivityPub::ProcessActivityService do subject { described_class.new } let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') } diff --git a/spec/workers/activitypub/processing_worker_spec.rb b/spec/workers/activitypub/processing_worker_spec.rb index c06ba63d39b..dd99a5d52d5 100644 --- a/spec/workers/activitypub/processing_worker_spec.rb +++ b/spec/workers/activitypub/processing_worker_spec.rb @@ -8,11 +8,11 @@ RSpec.describe ActivityPub::ProcessingWorker do let(:account) { Fabricate(:account) } describe '#perform' do - it 'delegates to ActivityPub::ProcessCollectionService' do - allow(ActivityPub::ProcessCollectionService).to receive(:new) - .and_return(instance_double(ActivityPub::ProcessCollectionService, call: nil)) + it 'delegates to ActivityPub::ProcessActivityService' do + allow(ActivityPub::ProcessActivityService).to receive(:new) + .and_return(instance_double(ActivityPub::ProcessActivityService, call: nil)) subject.perform(account.id, '') - expect(ActivityPub::ProcessCollectionService).to have_received(:new) + expect(ActivityPub::ProcessActivityService).to have_received(:new) end end end