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