diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-09-09 20:04:34 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-09-09 20:04:34 +0200 |
commit | 3cc47beb6e1f646baca64fdf56168e2f2e2bc726 (patch) | |
tree | 295d9442bec8fa7434b6a2c37a6cb835a3725dfd /app/lib/tag_manager.rb | |
parent | 735b4cc62e3fb9ef7a10b657c8e437ac0cb3d1fe (diff) |
Refactored generation of unique tags, URIs and object URLs into own classes,
as well as formatting of content
Diffstat (limited to 'app/lib/tag_manager.rb')
-rw-r--r-- | app/lib/tag_manager.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/app/lib/tag_manager.rb b/app/lib/tag_manager.rb new file mode 100644 index 000000000..4d29ca1f8 --- /dev/null +++ b/app/lib/tag_manager.rb @@ -0,0 +1,41 @@ +require 'singleton' + +class TagManager + include Singleton + include RoutingHelper + + def unique_tag(date, id, type) + "tag:#{Rails.configuration.x.local_domain},#{date.strftime('%Y-%m-%d')}:objectId=#{id}:objectType=#{type}" + end + + def unique_tag_to_local_id(tag, expected_type) + matches = Regexp.new("objectId=([\\d]+):objectType=#{expected_type}").match(tag) + return matches[1] unless matches.nil? + end + + def local_id?(id) + id.start_with?("tag:#{Rails.configuration.x.local_domain}") + end + + def uri_for(target) + return target.uri if target.respond_to?(:local?) && !target.local? + + case target.object_type + when :person + account_url(target) + else + unique_tag(target.stream_entry.created_at, target.stream_entry.activity_id, target.stream_entry.activity_type) + end + end + + def url_for(target) + return target.url if target.respond_to?(:local?) && !target.local? + + case target.object_type + when :person + account_url(target) + else + account_stream_entry_url(target.account, target.stream_entry) + end + end +end |