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.

45 lines
1.2 KiB

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