闭社主体 forked from https://github.com/tootsuite/mastodon
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
671 B

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