about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-06-18 22:43:01 +0200
committerGitHub <noreply@github.com>2018-06-18 22:43:01 +0200
commit908a9671d0e7bcf1c6bea180e2e13be84485694d (patch)
treea7f3fe3d56f7624421a1ff85f0b6ae843240e31f
parent50689f0d41b1f02c2d26c353571dfd15d8a4f186 (diff)
Serialize language into ActivityPub JSON (#7840)
* Serialize language into ActivityPub JSON

* Only use contentMap if language is present
-rw-r--r--app/serializers/activitypub/note_serializer.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/serializers/activitypub/note_serializer.rb b/app/serializers/activitypub/note_serializer.rb
index ddafb540d..eafd409ba 100644
--- a/app/serializers/activitypub/note_serializer.rb
+++ b/app/serializers/activitypub/note_serializer.rb
@@ -1,12 +1,15 @@
 # frozen_string_literal: true
 
 class ActivityPub::NoteSerializer < ActiveModel::Serializer
-  attributes :id, :type, :summary, :content,
+  attributes :id, :type, :summary,
              :in_reply_to, :published, :url,
              :attributed_to, :to, :cc, :sensitive,
              :atom_uri, :in_reply_to_atom_uri,
              :conversation
 
+  attribute :content, unless: :language?
+  attribute :content_map, if: :language?
+
   has_many :media_attachments, key: :attachment
   has_many :virtual_tags, key: :tag
 
@@ -26,6 +29,14 @@ class ActivityPub::NoteSerializer < ActiveModel::Serializer
     Formatter.instance.format(object)
   end
 
+  def content_map
+    { object.language => Formatter.instance.format(object) }
+  end
+
+  def language?
+    object.language.present?
+  end
+
   def in_reply_to
     return unless object.reply? && !object.thread.nil?