Merge branch 'develop' into feature/incoming_ostatus
[akkoma] / lib / pleroma / web / ostatus / activity_representer.ex
index 558c85df48d3cae3ec2a32a31bac6e57081032e3..367212fe142bd662a48057c1451afbcc6ea9c70d 100644 (file)
@@ -1,5 +1,5 @@
 defmodule Pleroma.Web.OStatus.ActivityRepresenter do
-  def to_simple_form(activity, user) do
+  def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user) do
     h = fn(str) -> [to_charlist(str)] end
 
     updated_at = activity.updated_at
@@ -7,14 +7,23 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do
     inserted_at = activity.inserted_at
     |> NaiveDateTime.to_iso8601
 
+    attachments = Enum.map(activity.data["object"]["attachment"] || [], fn(attachment) ->
+      url = hd(attachment["url"])
+      {:link, [rel: 'enclosure', href: to_charlist(url["href"]), type: to_charlist(url["mediaType"])], []}
+    end)
+
     [
       {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']},
       {:"activity:verb", ['http://activitystrea.ms/schema/1.0/post']},
-      {:id, h.(activity.data["id"])},
+      {:id, h.(activity.data["object"]["id"])},
       {:title, ['New note by #{user.nickname}']},
       {:content, [type: 'html'], h.(activity.data["object"]["content"])},
       {:published, h.(inserted_at)},
-      {:updated, h.(updated_at)}
-    ]
+      {:updated, h.(updated_at)},
+      {:"ostatus:conversation", [], h.(activity.data["context"])},
+      {:link, [href: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}
+    ] ++ attachments
   end
+
+  def to_simple_form(_,_), do: nil
 end