about summary refs log tree commit diff
path: root/app/helpers/atom_builder_helper.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-09-09 20:04:34 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-09 20:04:34 +0200
commit3cc47beb6e1f646baca64fdf56168e2f2e2bc726 (patch)
tree295d9442bec8fa7434b6a2c37a6cb835a3725dfd /app/helpers/atom_builder_helper.rb
parent735b4cc62e3fb9ef7a10b657c8e437ac0cb3d1fe (diff)
Refactored generation of unique tags, URIs and object URLs into own classes,
as well as formatting of content
Diffstat (limited to 'app/helpers/atom_builder_helper.rb')
-rw-r--r--app/helpers/atom_builder_helper.rb40
1 files changed, 8 insertions, 32 deletions
diff --git a/app/helpers/atom_builder_helper.rb b/app/helpers/atom_builder_helper.rb
index c8046182f..39ea20e31 100644
--- a/app/helpers/atom_builder_helper.rb
+++ b/app/helpers/atom_builder_helper.rb
@@ -16,7 +16,7 @@ module AtomBuilderHelper
   end
 
   def unique_id(xml, date, id, type)
-    xml.id_ unique_tag(date, id, type)
+    xml.id_ TagManager.instance.unique_tag(date, id, type)
   end
 
   def simple_id(xml, id)
@@ -97,32 +97,8 @@ module AtomBuilderHelper
     xml['thr'].send('in-reply-to', { ref: uri, href: url, type: 'text/html' })
   end
 
-  def uri_for_target(target)
-    if target.local?
-      if target.object_type == :person
-        account_url(target)
-      else
-        unique_tag(target.stream_entry.created_at, target.stream_entry.activity_id, target.stream_entry.activity_type)
-      end
-    else
-      target.uri
-    end
-  end
-
-  def url_for_target(target)
-    if target.local?
-      if target.object_type == :person
-        account_url(target)
-      else
-        account_stream_entry_url(target.account, target.stream_entry)
-      end
-    else
-      target.url
-    end
-  end
-
   def link_mention(xml, account)
-    xml.link(rel: 'mentioned', href: uri_for_target(account))
+    xml.link(rel: 'mentioned', href: TagManager.instance.uri_for(account))
   end
 
   def link_enclosure(xml, media)
@@ -145,7 +121,7 @@ module AtomBuilderHelper
 
   def conditionally_formatted(activity)
     if activity.is_a?(Status)
-      content_for_status(activity.reblog? ? activity.reblog : activity)
+      Formatter.instance.format(activity.reblog? ? activity.reblog : activity)
     elsif activity.nil?
       nil
     else
@@ -155,11 +131,11 @@ module AtomBuilderHelper
 
   def include_author(xml, account)
     object_type      xml, :person
-    uri              xml, uri_for_target(account)
+    uri              xml, TagManager.instance.uri_for(account)
     name             xml, account.username
     email            xml, account.local? ? "#{account.acct}@#{Rails.configuration.x.local_domain}" : account.acct
     summary          xml, account.note
-    link_alternate   xml, url_for_target(account)
+    link_alternate   xml, TagManager.instance.url_for(account)
     link_avatar      xml, account
     portable_contact xml, account
   end
@@ -176,7 +152,7 @@ module AtomBuilderHelper
 
     # Comments need thread element
     if stream_entry.threaded?
-      in_reply_to xml, uri_for_target(stream_entry.thread), url_for_target(stream_entry.thread)
+      in_reply_to xml, TagManager.instance.uri_for(stream_entry.thread), TagManager.instance.url_for(stream_entry.thread)
     end
 
     if stream_entry.targeted?
@@ -185,9 +161,9 @@ module AtomBuilderHelper
           include_author xml, stream_entry.target
         else
           object_type    xml, stream_entry.target.object_type
-          simple_id      xml, uri_for_target(stream_entry.target)
+          simple_id      xml, TagManager.instance.uri_for(stream_entry.target)
           title          xml, stream_entry.target.title
-          link_alternate xml, url_for_target(stream_entry.target)
+          link_alternate xml, TagManager.instance.url_for(stream_entry.target)
         end
 
         # Statuses have content and author