Add Mastodon StatusView.
[akkoma] / lib / pleroma / web / mastodon_api / views / status_view.ex
1 defmodule Pleroma.Web.MastodonAPI.StatusView do
2 use Pleroma.Web, :view
3 alias Pleroma.Web.MastodonAPI.{AccountView, StatusView}
4 alias Pleroma.User
5
6 def render("index.json", opts) do
7 render_many(opts.activities, StatusView, "status.json", opts)
8 end
9
10 def render("status.json", %{activity: %{data: %{"object" => object}} = activity}) do
11 user = User.get_cached_by_ap_id(activity.data["actor"])
12
13 like_count = object["like_count"] || 0
14 announcement_count = object["announcement_count"] || 0
15
16 tags = object["tag"] || []
17 sensitive = Enum.member?(tags, "nsfw")
18
19 mentions = activity.data["to"]
20 |> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end)
21 |> Enum.filter(&(&1))
22 |> Enum.map(fn (user) -> AccountView.render("mention.json", %{user: user}) end)
23
24 %{
25 id: activity.id,
26 uri: object["id"],
27 url: object["external_url"],
28 account: AccountView.render("account.json", %{user: user}),
29 in_reply_to_id: object["inReplyToStatusId"],
30 in_reply_to_account_id: nil,
31 reblog: nil,
32 content: HtmlSanitizeEx.basic_html(object["content"]),
33 created_at: object["published"],
34 reblogs_count: announcement_count,
35 favourites_count: like_count,
36 reblogged: false,
37 favourited: false, # fix
38 muted: false,
39 sensitive: sensitive,
40 spoiler_text: "",
41 visibility: "public",
42 media_attachments: [], # fix
43 mentions: mentions,
44 tags: [], # fix,
45 application: nil,
46 language: nil
47 }
48 end
49 end