Add categories to ostatus output.
authorRoger Braun <roger@rogerbraun.net>
Thu, 18 May 2017 16:18:27 +0000 (18:18 +0200)
committerRoger Braun <roger@rogerbraun.net>
Thu, 18 May 2017 16:18:27 +0000 (18:18 +0200)
lib/pleroma/web/ostatus/activity_representer.ex
test/support/factory.ex
test/web/ostatus/activity_representer_test.exs

index 02d15ea94a0bdc5c11bbc3f17571403be48fe0f2..ccf71218cbde338cb4cd2ef94f7ab7253846e0bd 100644 (file)
@@ -42,6 +42,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
     author = if with_author, do: [{:author, UserRepresenter.to_simple_form(user)}], else: []
     mentions = activity.data["to"] |> get_mentions
 
+    categories = (activity.data["object"]["tag"] || [])
+    |> Enum.map(fn (tag) -> {:category, [term: to_charlist(tag)], []} end)
+
     [
       {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']},
       {:"activity:verb", ['http://activitystrea.ms/schema/1.0/post']},
@@ -53,7 +56,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
       {:"ostatus:conversation", [], h.(activity.data["context"])},
       {:link, [href: h.(activity.data["context"]), rel: 'ostatus:conversation'], []},
       {:link, [type: ['application/atom+xml'], href: h.(activity.data["object"]["id"]), rel: 'self'], []}
-    ] ++ attachments ++ in_reply_to ++ author ++ mentions
+    ] ++ categories ++ attachments ++ in_reply_to ++ author ++ mentions
   end
 
   def to_simple_form(%{data: %{"type" => "Like"}} = activity, user, with_author) do
index ffc9c56dc4e3a835667790af4605e69428166a54..3cf35e3bcda990add7b0b4a105a705466cc52bda 100644 (file)
@@ -25,7 +25,8 @@ defmodule Pleroma.Factory do
       "published_at" => DateTime.utc_now() |> DateTime.to_iso8601,
       "likes" => [],
       "like_count" => 0,
-      "context" => "2hu"
+      "context" => "2hu",
+      "tag" => ["2hu"]
     }
 
     %Pleroma.Object{
index 969b2a854cf193f5880b83b189ad5240045f2662..7179cfb710155d6120baa74d963dc6d20a93f3a1 100644 (file)
@@ -27,6 +27,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
     <ostatus:conversation>#{note_activity.data["context"]}</ostatus:conversation>
     <link href="#{note_activity.data["context"]}" rel="ostatus:conversation" />
     <link type="application/atom+xml" href="#{note_activity.data["object"]["id"]}" rel="self" />
+    <category term="2hu"/>
     <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
     """