From bafd22ecf487774c252a271d668716b0e1c84c6c Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 3 May 2017 17:02:18 +0200 Subject: Fix #2706 - Always respond with 200 to PuSH payloads (#2733) Fix #2196 - Respond with 201 when Salmon accepted, 400 when unverified Fix #2629 - Correctly handle confirm_domain? for local accounts Unify rules for extracting author acct from XML, prefer , fall back to + (see also #2017, #2172) --- app/services/concerns/author_extractor.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/services/concerns/author_extractor.rb (limited to 'app/services/concerns') diff --git a/app/services/concerns/author_extractor.rb b/app/services/concerns/author_extractor.rb new file mode 100644 index 000000000..d99780e7d --- /dev/null +++ b/app/services/concerns/author_extractor.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module AuthorExtractor + def author_from_xml(xml) + # Try for acct + acct = xml.at_xpath('./xmlns:author/xmlns:email', xmlns: TagManager::XMLNS)&.content + + # Try + + if acct.blank? + username = xml.at_xpath('./xmlns:author/xmlns:name', xmlns: TagManager::XMLNS)&.content + uri = xml.at_xpath('./xmlns:author/xmlns:uri', xmlns: TagManager::XMLNS)&.content + + return nil if username.blank? || uri.blank? + + domain = Addressable::URI.parse(uri).normalize.host + acct = "#{username}@#{domain}" + end + + FollowRemoteAccountService.new.call(acct) + end +end -- cgit