闭社主体 forked from https://github.com/tootsuite/mastodon
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.

29 lines
814 B

8 years ago
8 years ago
8 years ago
  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 #{id} because: #{e}"
  21. nil
  22. end
  23. end