Handle comments.
[akkoma] / lib / pleroma / web / ostatus / activity_representer.ex
1 defmodule Pleroma.Web.OStatus.ActivityRepresenter do
2 alias Pleroma.Activity
3 require Logger
4
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)], []}]
8 else _e ->
9 Logger.debug("Couldn't find replied-to activity:")
10 Logger.debug(in_reply_to)
11 []
12 end
13 end
14
15 defp get_in_reply_to(_), do: []
16
17 def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user) do
18 h = fn(str) -> [to_charlist(str)] end
19
20 updated_at = activity.updated_at
21 |> NaiveDateTime.to_iso8601
22 inserted_at = activity.inserted_at
23 |> NaiveDateTime.to_iso8601
24
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"])], []}
28 end)
29
30 in_reply_to = get_in_reply_to(activity.data)
31
32 [
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
43 end
44
45 def to_simple_form(_,_), do: nil
46 end