mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
39 lines
820 B
Ruby
39 lines
820 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
class ActivityPub::ProcessCollectionService < BaseService
|
||
|
include JsonLdHelper
|
||
|
|
||
|
def call(body, account)
|
||
|
@account = account
|
||
|
@json = Oj.load(body, mode: :strict)
|
||
|
|
||
|
return if @account.suspended? || !supported_context?
|
||
|
|
||
|
case @json['type']
|
||
|
when 'Collection', 'CollectionPage'
|
||
|
process_items @json['items']
|
||
|
when 'OrderedCollection', 'OrderedCollectionPage'
|
||
|
process_items @json['orderedItems']
|
||
|
else
|
||
|
process_items [@json]
|
||
|
end
|
||
|
rescue Oj::ParseError
|
||
|
nil
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def process_items(items)
|
||
|
items.reverse_each.map { |item| process_item(item) }.compact
|
||
|
end
|
||
|
|
||
|
def supported_context?
|
||
|
super(@json)
|
||
|
end
|
||
|
|
||
|
def process_item(item)
|
||
|
activity = ActivityPub::Activity.factory(item, @account)
|
||
|
activity&.perform
|
||
|
end
|
||
|
end
|