Fix namespace parsing in Atom feeds

th-downstream
Eugen Rochko 8 years ago
parent 4f406d89b1
commit 61d7c88408

@ -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

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

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

Loading…
Cancel
Save