Federate object id for posts in ostatus.
[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 [{:"thr:in-reply-to", [ref: to_charlist(in_reply_to)], []}]
7 end
8
9 defp get_in_reply_to(_), do: []
10
11 def to_simple_form(%{data: %{"object" => %{"type" => "Note"}}} = activity, user) do
12 h = fn(str) -> [to_charlist(str)] end
13
14 updated_at = activity.updated_at
15 |> NaiveDateTime.to_iso8601
16 inserted_at = activity.inserted_at
17 |> NaiveDateTime.to_iso8601
18
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"])], []}
22 end)
23
24 in_reply_to = get_in_reply_to(activity.data)
25
26 [
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
37 end
38
39 def to_simple_form(_,_), do: nil
40 end