2016-11-16 02:56:29 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-24 22:57:29 +11:00
|
|
|
class ProcessFeedService < BaseService
|
2016-02-21 08:53:20 +11:00
|
|
|
def call(body, account)
|
|
|
|
xml = Nokogiri::XML(body)
|
2016-11-14 05:12:40 +11:00
|
|
|
xml.encoding = 'utf-8'
|
2016-11-08 11:32:34 +11:00
|
|
|
|
2017-04-08 21:26:03 +10:00
|
|
|
update_author(body, account)
|
2016-11-08 11:32:34 +11:00
|
|
|
process_entries(xml, account)
|
2016-03-25 12:13:30 +11:00
|
|
|
end
|
2016-02-21 08:53:20 +11:00
|
|
|
|
2016-03-25 12:13:30 +11:00
|
|
|
private
|
2016-02-29 00:26:26 +11:00
|
|
|
|
2017-04-08 21:26:03 +10:00
|
|
|
def update_author(body, account)
|
2017-04-06 05:41:50 +10:00
|
|
|
RemoteProfileUpdateWorker.perform_async(account.id, body.force_encoding('UTF-8'), true)
|
2016-11-08 11:32:34 +11:00
|
|
|
end
|
2016-02-24 11:28:53 +11:00
|
|
|
|
2016-11-08 11:32:34 +11:00
|
|
|
def process_entries(xml, account)
|
2017-07-19 00:39:47 +10:00
|
|
|
xml.xpath('//xmlns:entry', xmlns: TagManager::XMLNS).reverse_each.map { |entry| process_entry(entry, account) }.compact
|
2016-11-08 11:32:34 +11:00
|
|
|
end
|
2016-03-16 20:46:15 +11:00
|
|
|
|
2017-07-19 00:39:47 +10:00
|
|
|
def process_entry(xml, account)
|
2017-07-19 09:37:26 +10:00
|
|
|
activity = OStatus::Activity::General.new(xml, account)
|
2017-07-19 00:39:47 +10: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 08:39:03 +10:00
|
|
|
end
|
2016-02-21 08:53:20 +11:00
|
|
|
end
|