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