mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
54 lines
1.4 KiB
Ruby
54 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ActivityPub::ProcessFeaturedCollectionService
|
|
include JsonLdHelper
|
|
include Lockable
|
|
include Redisable
|
|
|
|
ITEMS_LIMIT = 150
|
|
|
|
def call(account, json, request_id: nil)
|
|
@account = account
|
|
@json = json
|
|
@request_id = request_id
|
|
return if non_matching_uri_hosts?(@account.uri, @json['id'])
|
|
|
|
with_redis_lock("collection:#{@json['id']}") do
|
|
return if @account.collections.exists?(uri: @json['id'])
|
|
|
|
@collection = @account.collections.create!(
|
|
local: false,
|
|
uri: @json['id'],
|
|
name: (@json['name'] || '')[0, Collection::NAME_LENGTH_HARD_LIMIT],
|
|
description_html: truncated_summary,
|
|
language:,
|
|
sensitive: @json['sensitive'],
|
|
discoverable: @json['discoverable'],
|
|
original_number_of_items: @json['totalItems'] || 0,
|
|
tag_name: @json.dig('topic', 'name')
|
|
)
|
|
|
|
process_items! if @json['totalItems'].positive?
|
|
|
|
@collection
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def truncated_summary
|
|
text = @json['summaryMap']&.values&.first || @json['summary'] || ''
|
|
text[0, Collection::DESCRIPTION_LENGTH_HARD_LIMIT]
|
|
end
|
|
|
|
def language
|
|
@json['summaryMap']&.keys&.first
|
|
end
|
|
|
|
def process_items!
|
|
@json['orderedItems'].take(ITEMS_LIMIT).each do |item_json|
|
|
ActivityPub::ProcessFeaturedItemWorker.perform_async(@collection.id, item_json, @request_id)
|
|
end
|
|
end
|
|
end
|