1 defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
2 use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
3 alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter}
7 def to_map(%Activity{data: %{"type" => "Follow"}} = activity, %{user: user} = opts) do
8 created_at = get_in(activity.data, ["published"])
13 "user" => UserRepresenter.to_map(user, opts),
15 "statusnet_html" => "", # TODO: add summary
18 "is_post_verb" => false,
19 "created_at" => created_at,
20 "in_reply_to_status_id" => nil,
24 def to_map(%Activity{} = activity, %{user: user} = opts) do
25 content = get_in(activity.data, ["object", "content"])
26 created_at = get_in(activity.data, ["object", "published"])
29 mentions = opts[:mentioned] || []
31 attentions = activity.data["to"]
32 |> Enum.map(fn (ap_id) -> Enum.find(mentions, fn(user) -> ap_id == user.ap_id end) end)
34 |> Enum.map(fn (user) -> UserRepresenter.to_map(user, opts) end)
38 "user" => UserRepresenter.to_map(user, opts),
40 "statusnet_html" => content,
41 "text" => HtmlSanitizeEx.strip_tags(content),
43 "is_post_verb" => true,
44 "created_at" => created_at,
45 "in_reply_to_status_id" => activity.data["object"]["inReplyToStatusId"],
46 "statusnet_conversation_id" => activity.data["object"]["statusnetConversationId"],
47 "attachments" => (activity.data["object"]["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts),
48 "attentions" => attentions
52 defp date_to_asctime(date) do
53 with {:ok, date, _offset} <- date |> DateTime.from_iso8601 do
54 Calendar.Strftime.strftime!(date, "%a %b %d %H:%M:%S %z %Y")