Better comparison of "local" domain

This commit is contained in:
Eugen Rochko 2016-10-06 16:36:16 +02:00
parent b62d8e2d5b
commit b23c4b488c
4 changed files with 7 additions and 3 deletions

View file

@ -5,7 +5,7 @@ class Api::V1::FollowsController < ApiController
def create def create
raise ActiveRecord::RecordNotFound if params[:uri].blank? raise ActiveRecord::RecordNotFound if params[:uri].blank?
@account = FollowService.new.call(current_user.account, params[:uri]).try(:target_account) @account = FollowService.new.call(current_user.account, params[:uri].strip).try(:target_account)
render action: :show render action: :show
end end
end end

View file

@ -17,6 +17,10 @@ class TagManager
id.start_with?("tag:#{Rails.configuration.x.local_domain}") id.start_with?("tag:#{Rails.configuration.x.local_domain}")
end end
def local_domain?(domain)
domain.nil? || domain.gsub(/[\/]/, '') == Rails.configuration.x.local_domain
end
def uri_for(target) def uri_for(target)
return target.uri if target.respond_to?(:local?) && !target.local? return target.uri if target.respond_to?(:local?) && !target.local?

View file

@ -7,7 +7,7 @@ class FollowRemoteAccountService < BaseService
def call(uri) def call(uri)
username, domain = uri.split('@') username, domain = uri.split('@')
return Account.find_local(username) if domain == Rails.configuration.x.local_domain || domain.nil? return Account.find_local(username) if TagManager.instance.local_domain?(domain)
account = Account.find_remote(username, domain) account = Account.find_remote(username, domain)

View file

@ -63,7 +63,7 @@ class ProcessFeedService < BaseService
href = Addressable::URI.parse(href_val) href = Addressable::URI.parse(href_val)
if href.host == Rails.configuration.x.local_domain if TagManager.instance.local_domain?(href.host)
# A local user is mentioned # A local user is mentioned
mentioned_account = Account.find_local(href.path.gsub('/users/', '')) mentioned_account = Account.find_local(href.path.gsub('/users/', ''))