Add Follow Activity representer
[akkoma] / lib / pleroma / web / twitter_api / representers / activity_representer.ex
1 defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
2 use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
3 alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter}
4 alias Pleroma.Activity
5
6 def to_map(%Activity{data: %{"type" => "Follow"}} = activity, %{user: user} = opts) do
7 %{
8 "id" => activity.id,
9 "user" => UserRepresenter.to_map(user, opts),
10 "attentions" => [],
11 "statusnet_html" => "", # TODO: add summary
12 "text" => "",
13 "is_local" => true,
14 "is_post_verb" => false,
15 "created_at" => get_in(activity.data, ["published"]),
16 "in_reply_to_status_id" => nil,
17 }
18 end
19
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"])
23
24 mentions = opts[:mentioned] || []
25
26 attentions = activity.data["to"]
27 |> Enum.map(fn (ap_id) -> Enum.find(mentions, fn(user) -> ap_id == user.ap_id end) end)
28 |> Enum.filter(&(&1))
29 |> Enum.map(fn (user) -> UserRepresenter.to_map(user, opts) end)
30
31 %{
32 "id" => activity.id,
33 "user" => UserRepresenter.to_map(user, opts),
34 "attentions" => [],
35 "statusnet_html" => content,
36 "text" => content,
37 "is_local" => true,
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
44 }
45 end
46 end