2016-11-15 09:56:29 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-09 13:04:34 -05:00
|
|
|
require 'singleton'
|
|
|
|
|
|
|
|
class TagManager
|
|
|
|
include Singleton
|
|
|
|
include RoutingHelper
|
|
|
|
|
2017-04-14 19:15:46 -05:00
|
|
|
def web_domain?(domain)
|
|
|
|
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.web_domain).zero?
|
|
|
|
end
|
|
|
|
|
2016-10-06 09:36:16 -05:00
|
|
|
def local_domain?(domain)
|
2016-11-15 09:56:29 -06:00
|
|
|
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
|
2016-10-06 09:36:16 -05:00
|
|
|
end
|
|
|
|
|
2017-04-24 19:47:31 -05:00
|
|
|
def normalize_domain(domain)
|
2017-05-04 19:23:01 -05:00
|
|
|
return if domain.nil?
|
|
|
|
|
2017-04-24 19:47:31 -05:00
|
|
|
uri = Addressable::URI.new
|
2017-05-04 19:23:01 -05:00
|
|
|
uri.host = domain.gsub(/[\/]/, '')
|
2017-07-15 10:24:35 -05:00
|
|
|
uri.normalized_host
|
2017-04-24 19:47:31 -05:00
|
|
|
end
|
|
|
|
|
2017-03-28 07:16:08 -05:00
|
|
|
def same_acct?(canonical, needle)
|
|
|
|
return true if canonical.casecmp(needle).zero?
|
2019-07-08 20:27:35 -05:00
|
|
|
|
2017-03-28 07:16:08 -05:00
|
|
|
username, domain = needle.split('@')
|
2019-07-08 20:27:35 -05:00
|
|
|
|
2017-03-28 07:16:08 -05:00
|
|
|
local_domain?(domain) && canonical.casecmp(username).zero?
|
|
|
|
end
|
|
|
|
|
2017-01-27 09:55:06 -06:00
|
|
|
def local_url?(url)
|
2017-04-24 19:47:31 -05:00
|
|
|
uri = Addressable::URI.parse(url).normalize
|
2017-01-27 09:55:06 -06:00
|
|
|
domain = uri.host + (uri.port ? ":#{uri.port}" : '')
|
2019-07-08 20:27:35 -05:00
|
|
|
|
2017-09-13 07:22:16 -05:00
|
|
|
TagManager.instance.web_domain?(domain)
|
2017-01-27 09:55:06 -06:00
|
|
|
end
|
2016-09-09 13:04:34 -05:00
|
|
|
end
|