2016-11-15 07:56:29 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-24 03:57:29 -08:00
|
|
|
class ProcessFeedService < BaseService
|
2016-02-20 13:53:20 -08:00
|
|
|
def call(body, account)
|
|
|
|
xml = Nokogiri::XML(body)
|
2016-11-13 10:12:40 -08:00
|
|
|
xml.encoding = 'utf-8'
|
2016-11-07 16:32:34 -08:00
|
|
|
|
2017-04-08 04:26:03 -07:00
|
|
|
update_author(body, account)
|
2016-11-07 16:32:34 -08:00
|
|
|
process_entries(xml, account)
|
2016-03-24 18:13:30 -07:00
|
|
|
end
|
2016-02-20 13:53:20 -08:00
|
|
|
|
2016-03-24 18:13:30 -07:00
|
|
|
private
|
2016-02-28 05:26:26 -08:00
|
|
|
|
2017-04-08 04:26:03 -07:00
|
|
|
def update_author(body, account)
|
2017-04-05 12:41:50 -07:00
|
|
|
RemoteProfileUpdateWorker.perform_async(account.id, body.force_encoding('UTF-8'), true)
|
2016-11-07 16:32:34 -08:00
|
|
|
end
|
2016-02-23 16:28:53 -08:00
|
|
|
|
2016-11-07 16:32:34 -08:00
|
|
|
def process_entries(xml, account)
|
2017-07-18 07:39:47 -07:00
|
|
|
xml.xpath('//xmlns:entry', xmlns: 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
|
|
|
|
2017-07-18 07:39:47 -07:00
|
|
|
def process_entry(xml, account)
|
2017-07-18 16:37:26 -07:00
|
|
|
activity = OStatus::Activity::General.new(xml, account)
|
2017-07-18 07:39:47 -07:00
|
|
|
activity.specialize&.perform if activity.status?
|
|
|
|
rescue ActiveRecord::RecordInvalid => e
|
2017-07-19 07:02:03 -07:00
|
|
|
Rails.logger.debug "Nothing was saved for #{activity.id} because: #{e}"
|
2017-07-18 07:39:47 -07:00
|
|
|
nil
|
2016-09-19 15:39:03 -07:00
|
|
|
end
|
2016-02-20 13:53:20 -08:00
|
|
|
end
|