logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

author_extractor.rb (733B)


  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)
  16. end
  17. end