about summary refs log tree commit diff
path: root/app/helpers/atom_builder_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/atom_builder_helper.rb')
-rw-r--r--app/helpers/atom_builder_helper.rb103
1 files changed, 65 insertions, 38 deletions
diff --git a/app/helpers/atom_builder_helper.rb b/app/helpers/atom_builder_helper.rb
index fb8f0976c..b750eeb07 100644
--- a/app/helpers/atom_builder_helper.rb
+++ b/app/helpers/atom_builder_helper.rb
@@ -90,6 +90,10 @@ module AtomBuilderHelper
     xml.link(rel: 'self', type: 'application/atom+xml', href: url)
   end
 
+  def link_next(xml, url)
+    xml.link(rel: 'next', type: 'application/atom+xml', href: url)
+  end
+
   def link_hub(xml, url)
     xml.link(rel: 'hub', href: url)
   end
@@ -120,6 +124,10 @@ module AtomBuilderHelper
     single_link_avatar(xml, account, :original, 120)
   end
 
+  def link_header(xml, account)
+    xml.link('rel' => 'header', 'type' => account.header_content_type, 'media:width' => 700, 'media:height' => 335, 'href' => full_asset_url(account.header.url(:original)))
+  end
+
   def logo(xml, url)
     xml.logo url
   end
@@ -143,7 +151,12 @@ module AtomBuilderHelper
     xml.link(:rel => 'mentioned', :href => TagManager::COLLECTIONS[:public], 'ostatus:object-type' => TagManager::TYPES[:collection])
   end
 
+  def privacy_scope(xml, level)
+    xml['mastodon'].scope(level)
+  end
+
   def include_author(xml, account)
+    simple_id        xml, TagManager.instance.uri_for(account)
     object_type      xml, :person
     uri              xml, TagManager.instance.uri_for(account)
     name             xml, account.username
@@ -151,7 +164,9 @@ module AtomBuilderHelper
     summary          xml, account.note
     link_alternate   xml, TagManager.instance.url_for(account)
     link_avatar      xml, account
+    link_header      xml, account
     portable_contact xml, account
+    privacy_scope    xml, account.locked? ? :private : :public
   end
 
   def rich_content(xml, activity)
@@ -162,6 +177,52 @@ module AtomBuilderHelper
     end
   end
 
+  def include_target(xml, target)
+    simple_id xml, TagManager.instance.uri_for(target)
+
+    if target.object_type == :person
+      include_author xml, target
+    else
+      object_type    xml, target.object_type
+      verb           xml, target.verb
+      title          xml, target.title
+      link_alternate xml, TagManager.instance.url_for(target)
+    end
+
+    # Statuses have content and author
+    return unless target.is_a?(Status)
+
+    rich_content xml, target
+    verb         xml, target.verb
+    published_at xml, target.created_at
+    updated_at   xml, target.updated_at
+
+    author(xml) do
+      include_author xml, target.account
+    end
+
+    if target.reply?
+      in_reply_to xml, TagManager.instance.uri_for(target.thread), TagManager.instance.url_for(target.thread)
+    end
+
+    link_visibility xml, target
+
+    target.mentions.each do |mention|
+      link_mention xml, mention.account
+    end
+
+    target.media_attachments.each do |media|
+      link_enclosure xml, media
+    end
+
+    target.tags.each do |tag|
+      category xml, tag.name
+    end
+
+    category(xml, 'nsfw') if target.sensitive?
+    privacy_scope(xml, target.visibility)
+  end
+
   def include_entry(xml, stream_entry)
     unique_id      xml, stream_entry.created_at, stream_entry.activity_id, stream_entry.activity_type
     published_at   xml, stream_entry.created_at
@@ -180,43 +241,7 @@ module AtomBuilderHelper
 
     if stream_entry.targeted?
       target(xml) do
-        simple_id xml, TagManager.instance.uri_for(stream_entry.target)
-
-        if stream_entry.target.object_type == :person
-          include_author xml, stream_entry.target
-        else
-          object_type    xml, stream_entry.target.object_type
-          title          xml, stream_entry.target.title
-          link_alternate xml, TagManager.instance.url_for(stream_entry.target)
-        end
-
-        # Statuses have content and author
-        if stream_entry.target.is_a?(Status)
-          rich_content xml, stream_entry.target
-          verb         xml, stream_entry.target.verb
-          published_at xml, stream_entry.target.created_at
-          updated_at   xml, stream_entry.target.updated_at
-
-          author(xml) do
-            include_author xml, stream_entry.target.account
-          end
-
-          link_visibility xml, stream_entry.target
-
-          stream_entry.target.mentions.each do |mention|
-            link_mention xml, mention.account
-          end
-
-          stream_entry.target.media_attachments.each do |media|
-            link_enclosure xml, media
-          end
-
-          stream_entry.target.tags.each do |tag|
-            category xml, tag.name
-          end
-
-          category(xml, 'nsfw') if stream_entry.target.sensitive?
-        end
+        include_target(xml, stream_entry.target)
       end
     end
 
@@ -237,6 +262,7 @@ module AtomBuilderHelper
     end
 
     category(xml, 'nsfw') if stream_entry.activity.sensitive?
+    privacy_scope(xml, stream_entry.activity.visibility)
   end
 
   private
@@ -249,10 +275,11 @@ module AtomBuilderHelper
                'xmlns:poco'     => TagManager::POCO_XMLNS,
                'xmlns:media'    => TagManager::MEDIA_XMLNS,
                'xmlns:ostatus'  => TagManager::OS_XMLNS,
+               'xmlns:mastodon' => TagManager::MTDN_XMLNS,
              }, &block)
   end
 
   def single_link_avatar(xml, account, size, px)
-    xml.link('rel' => 'avatar', 'type' => account.avatar_content_type, 'media:width' => px, 'media:height' => px, 'href' => full_asset_url(account.avatar.url(size, false)))
+    xml.link('rel' => 'avatar', 'type' => account.avatar_content_type, 'media:width' => px, 'media:height' => px, 'href' => full_asset_url(account.avatar.url(size)))
   end
 end