diff options
author | ThibG <thib@sitedethib.com> | 2017-04-09 18:43:48 +0200 |
---|---|---|
committer | Eugen <eugen@zeonfederated.com> | 2017-04-09 18:43:48 +0200 |
commit | d19ed183884690199a5890a409978a1204e3bf77 (patch) | |
tree | 173b427e483d36aa6ef34afdab19dda9801a2590 /app | |
parent | f0bd4394869305fc6605463efff53ecc6ff61046 (diff) |
Get handle from atom feed's author/email field instead of guessing from URL (#1344)
The goal of this change is to enhance Mastodon's handling of remote domains for which the APIs reside on a different host (see issue #1032). Indeed, when a remote user unknown to Mastodon is mentionned, only its profile URL (e.g. https://social.example.org/users/User) is known, and Mastodon has to build a @username@domain handle for it. To do so, Mastodon fetches the user's atom feed (e.g., https://social.example.org/users/User.atom) and uses its content to get the username part of the handle, and the URL's host part to build the domain (e.g., @User@social.example.org). This handle is then used for a Webfinger request. In the case where example.org serves the Webfinger info for @User@example.org and all feeds and APIs are hosted at social.example.org, Mastodon will still build @User@social.example.org and fail at resolving the account's details through Webfinger. This patch changes this behaviour by using the author's email address from the atom feed to build the handle. In Mastodon-generated atom feeds, the email address is always the handle it expects for federation.
Diffstat (limited to 'app')
-rw-r--r-- | app/services/fetch_remote_account_service.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/app/services/fetch_remote_account_service.rb b/app/services/fetch_remote_account_service.rb index 6a6a696d6..50ffc47c6 100644 --- a/app/services/fetch_remote_account_service.rb +++ b/app/services/fetch_remote_account_service.rb @@ -19,11 +19,16 @@ class FetchRemoteAccountService < BaseService xml = Nokogiri::XML(body) xml.encoding = 'utf-8' - url_parts = Addressable::URI.parse(url) - username = xml.at_xpath('//xmlns:author/xmlns:name').try(:content) - domain = url_parts.host + email = xml.at_xpath('//xmlns:author/xmlns:email').try(:content) + if email.nil? + url_parts = Addressable::URI.parse(url) + username = xml.at_xpath('//xmlns:author/xmlns:name').try(:content) + domain = url_parts.host + else + username, domain = email.split('@') + end - return nil if username.nil? + return nil if username.nil? || domain.nil? Rails.logger.debug "Going to webfinger #{username}@#{domain}" |