Fix namespace parsing in Atom feeds

lolsob-rspec
Eugen Rochko 2016-10-10 18:05:52 +02:00
parent 4f406d89b1
commit 61d7c88408
3 changed files with 23 additions and 16 deletions

View File

@ -1,4 +1,7 @@
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
# @param [String] body Atom feed
# @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
unless status.new_record?
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.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)
return status
@ -144,8 +147,8 @@ class ProcessFeedService < BaseService
end
def fetch_remote_status(xml)
username = xml.at_xpath('./activity:object/xmlns:author/xmlns:name').content
url = xml.at_xpath('./activity:object/xmlns:author/xmlns:uri').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', activity: ACTIVITY_NS).content
domain = Addressable::URI.parse(url).host
account = Account.find_remote(username, domain)
@ -178,19 +181,19 @@ class ProcessFeedService < BaseService
end
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
nil
end
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
nil
end
def target_id(xml)
xml.at_xpath('.//activity:object/xmlns:id').content
xml.at_xpath('.//activity:object/xmlns:id', activity: ACTIVITY_NS).content
rescue
nil
end
@ -206,21 +209,21 @@ class ProcessFeedService < BaseService
end
def target_content(xml)
xml.at_xpath('.//activity:object/xmlns:content').content
xml.at_xpath('.//activity:object/xmlns:content', activity: ACTIVITY_NS).content
end
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
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
:activity
end
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
:post
end

View File

@ -1,4 +1,6 @@
class ProcessInteractionService < BaseService
ACTIVITY_NS = 'http://activitystrea.ms/spec/1.0/'.freeze
# Record locally the remote interaction with our user
# @param [String] envelope Salmon envelope
# @param [Account] target_account Account the Salmon was addressed to
@ -53,7 +55,7 @@ class ProcessInteractionService < BaseService
end
def verb(xml)
xml.at_xpath('//activity:verb').content.gsub('http://activitystrea.ms/schema/1.0/', '').gsub('http://ostatus.org/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
:post
end
@ -92,7 +94,7 @@ class ProcessInteractionService < BaseService
end
def activity_id(xml)
xml.at_xpath('//activity:object/xmlns:id').content
xml.at_xpath('//activity:object/xmlns:id', activity: ACTIVITY_NS).content
end
def salmon

View File

@ -1,15 +1,17 @@
class UpdateRemoteProfileService < BaseService
POCO_NS = 'http://portablecontacts.net/spec/1.0'
def call(author_xml, account)
return if author_xml.nil?
if author_xml.at_xpath('./poco:displayName').nil?
if author_xml.at_xpath('./poco:displayName', poco: POCO_NS).nil?
account.display_name = account.username
else
account.display_name = author_xml.at_xpath('./poco:displayName').content
account.display_name = author_xml.at_xpath('./poco:displayName', poco: POCO_NS).content
end
unless author_xml.at_xpath('./poco:note').nil?
account.note = author_xml.at_xpath('./poco:note').content
account.note = author_xml.at_xpath('./poco:note', poco: POCO_NS).content
end
unless author_xml.at_xpath('./xmlns:link[@rel="avatar"]').nil?