1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00
mastodon/app/services/process_feed_service.rb

32 lines
880 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-02-24 03:57:29 -08:00
class ProcessFeedService < BaseService
def call(body, account, options = {})
@options = options
2016-02-20 13:53:20 -08:00
xml = Nokogiri::XML(body)
xml.encoding = 'utf-8'
2016-11-07 16:32:34 -08:00
update_author(body, account)
2016-11-07 16:32:34 -08:00
process_entries(xml, account)
end
2016-02-20 13:53:20 -08:00
private
def update_author(body, account)
RemoteProfileUpdateWorker.perform_async(account.id, body.force_encoding('UTF-8'), true)
2016-11-07 16:32:34 -08:00
end
2016-11-07 16:32:34 -08:00
def process_entries(xml, account)
2017-09-19 09:08:08 -07:00
xml.xpath('//xmlns:entry', xmlns: OStatus::TagManager::XMLNS).reverse_each.map { |entry| process_entry(entry, account) }.compact
2016-11-07 16:32:34 -08:00
end
2016-03-16 02:46:15 -07:00
def process_entry(xml, account)
activity = OStatus::Activity::General.new(xml, account, @options)
activity.specialize&.perform if activity.status?
rescue ActiveRecord::RecordInvalid => e
Rails.logger.debug "Nothing was saved for #{activity.id} because: #{e}"
nil
end
2016-02-20 13:53:20 -08:00
end