1
0

process_feed_service.rb 823 B

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