New service to fetch remote collections (#38298)

This commit is contained in:
David Roetzel
2026-03-19 15:27:02 +01:00
committed by GitHub
parent 605b5b91c9
commit f43969a0eb
3 changed files with 87 additions and 1 deletions

View File

@@ -0,0 +1,22 @@
# frozen_string_literal: true
class ActivityPub::FetchRemoteFeaturedCollectionService < BaseService
include JsonLdHelper
def call(uri, on_behalf_of = nil)
json = fetch_resource(uri, true, on_behalf_of)
return unless supported_context?(json)
return unless json['type'] == 'FeaturedCollection'
# Fetching an unknown account should eventually also fetch its
# collections, so it should be OK to only handle known accounts here
account = Account.find_by(uri: json['attributedTo'])
return unless account
existing_collection = account.collections.find_by(uri:)
return existing_collection if existing_collection.present?
ActivityPub::ProcessFeaturedCollectionService.new.call(account, json)
end
end

View File

@@ -27,7 +27,7 @@ class ActivityPub::ProcessFeaturedCollectionService
tag_name: @json.dig('topic', 'name')
)
process_items!
process_items! if @json['totalItems'].positive?
@collection
end