You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
820 B

  1. # frozen_string_literal: true
  2. class ActivityPub::ProcessCollectionService < BaseService
  3. include JsonLdHelper
  4. def call(body, account)
  5. @account = account
  6. @json = Oj.load(body, mode: :strict)
  7. return if @account.suspended? || !supported_context?
  8. case @json['type']
  9. when 'Collection', 'CollectionPage'
  10. process_items @json['items']
  11. when 'OrderedCollection', 'OrderedCollectionPage'
  12. process_items @json['orderedItems']
  13. else
  14. process_items [@json]
  15. end
  16. rescue Oj::ParseError
  17. nil
  18. end
  19. private
  20. def process_items(items)
  21. items.reverse_each.map { |item| process_item(item) }.compact
  22. end
  23. def supported_context?
  24. super(@json)
  25. end
  26. def process_item(item)
  27. activity = ActivityPub::Activity.factory(item, @account)
  28. activity&.perform
  29. end
  30. end