1 defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
2 use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
3 alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter}
6 def to_map(%Activity{data: %{"type" => "Follow"}} = activity, %{user: user} = opts) do
9 "user" => UserRepresenter.to_map(user, opts),
11 "statusnet_html" => "", # TODO: add summary
14 "is_post_verb" => false,
15 "created_at" => get_in(activity.data, ["published"]),
16 "in_reply_to_status_id" => nil,
20 def to_map(%Activity{} = activity, %{user: user} = opts) do
21 content = get_in(activity.data, ["object", "content"])
22 published = get_in(activity.data, ["object", "published"])
24 mentions = opts[:mentioned] || []
26 attentions = activity.data["to"]
27 |> Enum.map(fn (ap_id) -> Enum.find(mentions, fn(user) -> ap_id == user.ap_id end) end)
29 |> Enum.map(fn (user) -> UserRepresenter.to_map(user, opts) end)
33 "user" => UserRepresenter.to_map(user, opts),
35 "statusnet_html" => content,
38 "is_post_verb" => true,
39 "created_at" => published,
40 "in_reply_to_status_id" => activity.data["object"]["inReplyToStatusId"],
41 "statusnet_conversation_id" => activity.data["object"]["statusnetConversationId"],
42 "attachments" => (activity.data["object"]["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts),
43 "attentions" => attentions