1 defmodule Pleroma.Web.OStatus.ActivityRepresenter do
5 defp get_in_reply_to(%{"object" => %{ "inReplyTo" => in_reply_to}}) do
6 [{:"thr:in-reply-to", [ref: to_charlist(in_reply_to)], []}]
9 defp get_in_reply_to(_), do: []
11 def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user) do
12 h = fn(str) -> [to_charlist(str)] end
14 updated_at = activity.updated_at
15 |> NaiveDateTime.to_iso8601
16 inserted_at = activity.inserted_at
17 |> NaiveDateTime.to_iso8601
19 attachments = Enum.map(activity.data["object"]["attachment"] || [], fn(attachment) ->
20 url = hd(attachment["url"])
21 {:link, [rel: 'enclosure', href: to_charlist(url["href"]), type: to_charlist(url["mediaType"])], []}
24 in_reply_to = get_in_reply_to(activity.data)
27 {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']},
28 {:"activity:verb", ['http://activitystrea.ms/schema/1.0/post']},
29 {:id, h.(activity.data["object"]["id"])}, # For notes, federate the object id.
30 {:title, ['New note by #{user.nickname}']},
31 {:content, [type: 'html'], h.(activity.data["object"]["content"])},
32 {:published, h.(inserted_at)},
33 {:updated, h.(updated_at)},
34 {:"ostatus:conversation", [], h.(activity.data["context"])},
35 {:link, [href: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}
36 ] ++ attachments ++ in_reply_to
39 def to_simple_form(_,_), do: nil