Fix compatibility with Friendica regarding pinned posts (#18254)
* Fix multiple database queries when fetching pinned posts for remote account * Fix compatibility with Friendica regarding pinned posts Fixes #18066 * Add tests
This commit is contained in:
parent
6b7765a73b
commit
71d02ffcf3
2 changed files with 148 additions and 13 deletions
|
@ -7,20 +7,34 @@ class ActivityPub::FetchFeaturedCollectionService < BaseService
|
|||
return if account.featured_collection_url.blank? || account.suspended? || account.local?
|
||||
|
||||
@account = account
|
||||
@json = fetch_resource(@account.featured_collection_url, true)
|
||||
@json = fetch_resource(@account.featured_collection_url, true, local_follower)
|
||||
|
||||
return unless supported_context?
|
||||
return unless supported_context?(@json)
|
||||
|
||||
case @json['type']
|
||||
when 'Collection', 'CollectionPage'
|
||||
process_items @json['items']
|
||||
when 'OrderedCollection', 'OrderedCollectionPage'
|
||||
process_items @json['orderedItems']
|
||||
end
|
||||
process_items(collection_items(@json))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def collection_items(collection)
|
||||
collection = fetch_collection(collection['first']) if collection['first'].present?
|
||||
return unless collection.is_a?(Hash)
|
||||
|
||||
case collection['type']
|
||||
when 'Collection', 'CollectionPage'
|
||||
collection['items']
|
||||
when 'OrderedCollection', 'OrderedCollectionPage'
|
||||
collection['orderedItems']
|
||||
end
|
||||
end
|
||||
|
||||
def fetch_collection(collection_or_uri)
|
||||
return collection_or_uri if collection_or_uri.is_a?(Hash)
|
||||
return if invalid_origin?(collection_or_uri)
|
||||
|
||||
fetch_resource_without_id_validation(collection_or_uri, nil, true, local_follower)
|
||||
end
|
||||
|
||||
def process_items(items)
|
||||
status_ids = items.filter_map do |item|
|
||||
uri = value_or_id(item)
|
||||
|
@ -53,11 +67,9 @@ class ActivityPub::FetchFeaturedCollectionService < BaseService
|
|||
end
|
||||
end
|
||||
|
||||
def supported_context?
|
||||
super(@json)
|
||||
end
|
||||
|
||||
def local_follower
|
||||
@local_follower ||= @account.followers.local.without_suspended.first
|
||||
return @local_follower if defined?(@local_follower)
|
||||
|
||||
@local_follower = @account.followers.local.without_suspended.first
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue