mirror of
https://github.com/mastodon/mastodon.git
synced 2026-09-12 12:07:51 -05:00
Remove processing of collections of activities (#39932)
This commit is contained in:
@@ -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'])
|
||||
@@ -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
|
||||
|
||||
@@ -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') }
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user