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