1 defmodule Pleroma.Web.OStatus.ActivityRepresenter do
5 defp get_in_reply_to(%{"object" => %{ "inReplyTo" => in_reply_to}}) do
6 with %Activity{data: %{"id" => id}} <- Activity.get_create_activity_by_object_ap_id(in_reply_to) do
7 [{:"thr:in-reply-to", [ref: to_charlist(id)], []}]
9 Logger.debug("Couldn't find replied-to activity:")
10 Logger.debug(in_reply_to)
15 defp get_in_reply_to(_), do: []
17 def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user) do
18 h = fn(str) -> [to_charlist(str)] end
20 updated_at = activity.updated_at
21 |> NaiveDateTime.to_iso8601
22 inserted_at = activity.inserted_at
23 |> NaiveDateTime.to_iso8601
25 attachments = Enum.map(activity.data["object"]["attachment"] || [], fn(attachment) ->
26 url = hd(attachment["url"])
27 {:link, [rel: 'enclosure', href: to_charlist(url["href"]), type: to_charlist(url["mediaType"])], []}
30 in_reply_to = get_in_reply_to(activity.data)
33 {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/note']},
34 {:"activity:verb", ['http://activitystrea.ms/schema/1.0/post']},
35 {:id, h.(activity.data["id"])},
36 {:title, ['New note by #{user.nickname}']},
37 {:content, [type: 'html'], h.(activity.data["object"]["content"])},
38 {:published, h.(inserted_at)},
39 {:updated, h.(updated_at)},
40 {:"ostatus:conversation", [], h.(activity.data["context"])},
41 {:link, [href: h.(activity.data["context"]), rel: 'ostatus:conversation'], []}
42 ] ++ attachments ++ in_reply_to
45 def to_simple_form(_,_), do: nil