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