logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

tag_manager.rb (1184B)


  1. # frozen_string_literal: true
  2. require 'singleton'
  3. class TagManager
  4. include Singleton
  5. include RoutingHelper
  6. def web_domain?(domain)
  7. domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.web_domain).zero?
  8. end
  9. def local_domain?(domain)
  10. domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
  11. end
  12. def normalize_domain(domain)
  13. return if domain.nil?
  14. uri = Addressable::URI.new
  15. uri.host = domain.gsub(/[\/]/, '')
  16. uri.normalized_host
  17. end
  18. def same_acct?(canonical, needle)
  19. return true if canonical.casecmp(needle).zero?
  20. username, domain = needle.split('@')
  21. local_domain?(domain) && canonical.casecmp(username).zero?
  22. end
  23. def local_url?(url)
  24. uri = Addressable::URI.parse(url).normalize
  25. domain = uri.host + (uri.port ? ":#{uri.port}" : '')
  26. TagManager.instance.web_domain?(domain)
  27. end
  28. def url_for(target)
  29. return target.url if target.respond_to?(:local?) && !target.local?
  30. case target.object_type
  31. when :person
  32. short_account_url(target)
  33. when :note, :comment, :activity
  34. short_account_status_url(target.account, target)
  35. end
  36. end
  37. end