|
|
@ -1,4 +1,7 @@ |
|
|
|
class ProcessFeedService < BaseService |
|
|
|
class ProcessFeedService < BaseService |
|
|
|
|
|
|
|
ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'.freeze |
|
|
|
|
|
|
|
THREAD_NS = 'http://purl.org/syndication/thread/1.0'.freeze |
|
|
|
|
|
|
|
|
|
|
|
# Create local statuses from an Atom feed |
|
|
|
# Create local statuses from an Atom feed |
|
|
|
# @param [String] body Atom feed |
|
|
|
# @param [String] body Atom feed |
|
|
|
# @param [Account] account Account this feed belongs to |
|
|
|
# @param [Account] account Account this feed belongs to |
|
|
@ -42,10 +45,10 @@ class ProcessFeedService < BaseService |
|
|
|
# Also record all media attachments for the status and for the reblogged status if present |
|
|
|
# Also record all media attachments for the status and for the reblogged status if present |
|
|
|
unless status.new_record? |
|
|
|
unless status.new_record? |
|
|
|
record_remote_mentions(status, entry.xpath('./xmlns:link[@rel="mentioned"]')) |
|
|
|
record_remote_mentions(status, entry.xpath('./xmlns:link[@rel="mentioned"]')) |
|
|
|
record_remote_mentions(status.reblog, entry.xpath('./activity:object/xmlns:link[@rel="mentioned"]')) if status.reblog? |
|
|
|
record_remote_mentions(status.reblog, entry.xpath('./activity:object/xmlns:link[@rel="mentioned"]', activity: ACTIVITY_NS)) if status.reblog? |
|
|
|
|
|
|
|
|
|
|
|
process_attachments(entry, status) |
|
|
|
process_attachments(entry, status) |
|
|
|
process_attachments(entry.xpath('./activity:object'), status.reblog) if status.reblog? |
|
|
|
process_attachments(entry.xpath('./activity:object', activity: ACTIVITY_NS), status.reblog) if status.reblog? |
|
|
|
|
|
|
|
|
|
|
|
DistributionWorker.perform_async(status.id) |
|
|
|
DistributionWorker.perform_async(status.id) |
|
|
|
return status |
|
|
|
return status |
|
|
@ -144,8 +147,8 @@ class ProcessFeedService < BaseService |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def fetch_remote_status(xml) |
|
|
|
def fetch_remote_status(xml) |
|
|
|
username = xml.at_xpath('./activity:object/xmlns:author/xmlns:name').content |
|
|
|
username = xml.at_xpath('./activity:object/xmlns:author/xmlns:name', activity: ACTIVITY_NS).content |
|
|
|
url = xml.at_xpath('./activity:object/xmlns:author/xmlns:uri').content |
|
|
|
url = xml.at_xpath('./activity:object/xmlns:author/xmlns:uri', activity: ACTIVITY_NS).content |
|
|
|
domain = Addressable::URI.parse(url).host |
|
|
|
domain = Addressable::URI.parse(url).host |
|
|
|
account = Account.find_remote(username, domain) |
|
|
|
account = Account.find_remote(username, domain) |
|
|
|
|
|
|
|
|
|
|
@ -178,19 +181,19 @@ class ProcessFeedService < BaseService |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def thread_id(xml) |
|
|
|
def thread_id(xml) |
|
|
|
xml.at_xpath('./thr:in-reply-to').attribute('ref').value |
|
|
|
xml.at_xpath('./thr:in-reply-to', thr: THREAD_NS).attribute('ref').value |
|
|
|
rescue |
|
|
|
rescue |
|
|
|
nil |
|
|
|
nil |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def thread_href(xml) |
|
|
|
def thread_href(xml) |
|
|
|
xml.at_xpath('./thr:in-reply-to').attribute('href').value |
|
|
|
xml.at_xpath('./thr:in-reply-to', thr: THREAD_NS).attribute('href').value |
|
|
|
rescue |
|
|
|
rescue |
|
|
|
nil |
|
|
|
nil |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def target_id(xml) |
|
|
|
def target_id(xml) |
|
|
|
xml.at_xpath('.//activity:object/xmlns:id').content |
|
|
|
xml.at_xpath('.//activity:object/xmlns:id', activity: ACTIVITY_NS).content |
|
|
|
rescue |
|
|
|
rescue |
|
|
|
nil |
|
|
|
nil |
|
|
|
end |
|
|
|
end |
|
|
@ -206,21 +209,21 @@ class ProcessFeedService < BaseService |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def target_content(xml) |
|
|
|
def target_content(xml) |
|
|
|
xml.at_xpath('.//activity:object/xmlns:content').content |
|
|
|
xml.at_xpath('.//activity:object/xmlns:content', activity: ACTIVITY_NS).content |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def target_url(xml) |
|
|
|
def target_url(xml) |
|
|
|
xml.at_xpath('.//activity:object/xmlns:link[@rel="alternate"]').attribute('href').value |
|
|
|
xml.at_xpath('.//activity:object/xmlns:link[@rel="alternate"]', activity: ACTIVITY_NS).attribute('href').value |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def object_type(xml) |
|
|
|
def object_type(xml) |
|
|
|
xml.at_xpath('./activity:object-type').content.gsub('http://activitystrea.ms/schema/1.0/', '').to_sym |
|
|
|
xml.at_xpath('./activity:object-type', activity: ACTIVITY_NS).content.gsub('http://activitystrea.ms/schema/1.0/', '').gsub('http://ostatus.org/schema/1.0/', '').to_sym |
|
|
|
rescue |
|
|
|
rescue |
|
|
|
:activity |
|
|
|
:activity |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def verb(xml) |
|
|
|
def verb(xml) |
|
|
|
xml.at_xpath('./activity:verb').content.gsub('http://activitystrea.ms/schema/1.0/', '').to_sym |
|
|
|
xml.at_xpath('./activity:verb', activity: ACTIVITY_NS).content.gsub('http://activitystrea.ms/schema/1.0/', '').gsub('http://ostatus.org/schema/1.0/', '').to_sym |
|
|
|
rescue |
|
|
|
rescue |
|
|
|
:post |
|
|
|
:post |
|
|
|
end |
|
|
|
end |
|
|
|