You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
749 B

  1. # frozen_string_literal: true
  2. module AuthorExtractor
  3. def author_from_xml(xml, update_profile = true)
  4. return nil if xml.nil?
  5. # Try <email> for acct
  6. acct = xml.at_xpath('./xmlns:author/xmlns:email', xmlns: OStatus::TagManager::XMLNS)&.content
  7. # Try <name> + <uri>
  8. if acct.blank?
  9. username = xml.at_xpath('./xmlns:author/xmlns:name', xmlns: OStatus::TagManager::XMLNS)&.content
  10. uri = xml.at_xpath('./xmlns:author/xmlns:uri', xmlns: OStatus::TagManager::XMLNS)&.content
  11. return nil if username.blank? || uri.blank?
  12. domain = Addressable::URI.parse(uri).normalized_host
  13. acct = "#{username}@#{domain}"
  14. end
  15. ResolveAccountService.new.call(acct, update_profile: update_profile)
  16. end
  17. end