You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. require 'singleton'
  3. class TagManager
  4. include Singleton
  5. include RoutingHelper
  6. def unique_tag(date, id, type)
  7. "tag:#{Rails.configuration.x.local_domain},#{date.strftime('%Y-%m-%d')}:objectId=#{id}:objectType=#{type}"
  8. end
  9. def unique_tag_to_local_id(tag, expected_type)
  10. matches = Regexp.new("objectId=([\\d]+):objectType=#{expected_type}").match(tag)
  11. return matches[1] unless matches.nil?
  12. end
  13. def local_id?(id)
  14. id.start_with?("tag:#{Rails.configuration.x.local_domain}")
  15. end
  16. def local_domain?(domain)
  17. domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
  18. end
  19. def uri_for(target)
  20. return target.uri if target.respond_to?(:local?) && !target.local?
  21. case target.object_type
  22. when :person
  23. account_url(target)
  24. else
  25. unique_tag(target.stream_entry.created_at, target.stream_entry.activity_id, target.stream_entry.activity_type)
  26. end
  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. account_url(target)
  33. else
  34. account_stream_entry_url(target.account, target.stream_entry)
  35. end
  36. end
  37. end