Add `account_activation_required` to /api/v1/instance
[akkoma] / lib / pleroma / web / admin_api / views / report_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.AdminAPI.ReportView do
6 use Pleroma.Web, :view
7
8 alias Pleroma.HTML
9 alias Pleroma.User
10 alias Pleroma.Web.AdminAPI
11 alias Pleroma.Web.AdminAPI.Report
12 alias Pleroma.Web.CommonAPI.Utils
13 alias Pleroma.Web.MastodonAPI.StatusView
14
15 defdelegate merge_account_views(user), to: AdminAPI.AccountView
16
17 def render("index.json", %{reports: reports}) do
18 %{
19 reports:
20 reports[:items]
21 |> Enum.map(&Report.extract_report_info(&1))
22 |> Enum.map(&render(__MODULE__, "show.json", &1))
23 |> Enum.reverse(),
24 total: reports[:total]
25 }
26 end
27
28 def render("show.json", %{report: report, user: user, account: account, statuses: statuses}) do
29 created_at = Utils.to_masto_date(report.data["published"])
30
31 content =
32 unless is_nil(report.data["content"]) do
33 HTML.filter_tags(report.data["content"])
34 else
35 nil
36 end
37
38 %{
39 id: report.id,
40 account: merge_account_views(account),
41 actor: merge_account_views(user),
42 content: content,
43 created_at: created_at,
44 statuses:
45 StatusView.render("index.json", %{
46 activities: statuses,
47 as: :activity
48 }),
49 state: report.data["state"],
50 notes: render(__MODULE__, "index_notes.json", %{notes: report.report_notes})
51 }
52 end
53
54 def render("index_notes.json", %{notes: notes}) when is_list(notes) do
55 Enum.map(notes, &render(__MODULE__, "show_note.json", &1))
56 end
57
58 def render("index_notes.json", _), do: []
59
60 def render("show_note.json", %{
61 id: id,
62 content: content,
63 user_id: user_id,
64 inserted_at: inserted_at
65 }) do
66 user = User.get_by_id(user_id)
67
68 %{
69 id: id,
70 content: content,
71 user: merge_account_views(user),
72 created_at: Utils.to_masto_date(inserted_at)
73 }
74 end
75 end