mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
New service to fetch remote collections (#38298)
This commit is contained in:
@@ -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
|
||||
@@ -27,7 +27,7 @@ class ActivityPub::ProcessFeaturedCollectionService
|
||||
tag_name: @json.dig('topic', 'name')
|
||||
)
|
||||
|
||||
process_items!
|
||||
process_items! if @json['totalItems'].positive?
|
||||
|
||||
@collection
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user