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.

31 lines
877 B

8 years ago
8 years ago
8 years ago
  1. # frozen_string_literal: true
  2. class ProcessFeedService < BaseService
  3. def call(body, account, **options)
  4. @options = options
  5. xml = Nokogiri::XML(body)
  6. xml.encoding = 'utf-8'
  7. update_author(body, account)
  8. process_entries(xml, account)
  9. end
  10. private
  11. def update_author(body, account)
  12. RemoteProfileUpdateWorker.perform_async(account.id, body.force_encoding('UTF-8'), true)
  13. end
  14. def process_entries(xml, account)
  15. xml.xpath('//xmlns:entry', xmlns: OStatus::TagManager::XMLNS).reverse_each.map { |entry| process_entry(entry, account) }.compact
  16. end
  17. def process_entry(xml, account)
  18. activity = OStatus::Activity::General.new(xml, account, @options)
  19. activity.specialize&.perform if activity.status?
  20. rescue ActiveRecord::RecordInvalid => e
  21. Rails.logger.debug "Nothing was saved for #{activity.id} because: #{e}"
  22. nil
  23. end
  24. end