diff --git a/app/controllers/api/v1/account_by_username_controller.rb b/app/controllers/api/v1/account_by_username_controller.rb index 7fb82d23..2d9b8774 100644 --- a/app/controllers/api/v1/account_by_username_controller.rb +++ b/app/controllers/api/v1/account_by_username_controller.rb @@ -11,12 +11,7 @@ class Api::V1::AccountByUsernameController < Api::BaseController end def set_account - username, domain = params[:username].split("@") - if domain - @account = Account.find_remote!(username, domain) - else - @account = Account.find_local!(username) - end + @account = Account.find_acct!(params[:username]) end def check_account_suspension diff --git a/app/models/concerns/account_finder_concern.rb b/app/models/concerns/account_finder_concern.rb index ccd7bfa1..f0b93df6 100644 --- a/app/models/concerns/account_finder_concern.rb +++ b/app/models/concerns/account_finder_concern.rb @@ -12,6 +12,10 @@ module AccountFinderConcern find_remote(username, domain) || raise(ActiveRecord::RecordNotFound) end + def find_acct!(acct) + find_acct(acct) || raise(ActiveRecord::RecordNotFound) + end + def representative find_local(Setting.site_contact_username.strip.gsub(/\A@/, '')) || Account.local.without_suspended.first end @@ -23,6 +27,11 @@ module AccountFinderConcern def find_remote(username, domain) AccountFinder.new(username, domain).account end + + def find_acct(acct) + username, domain = acct.split("@") + find_remote(username, domain) + end end class AccountFinder