Enhance reports in Pleroma API: index, show
[akkoma] / lib / pleroma / web / pleroma_api / views / report_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.PleromaAPI.ReportView do
6 use Pleroma.Web, :view
7
8 alias Pleroma.HTML
9 alias Pleroma.Web.AdminAPI.Report
10 alias Pleroma.Web.CommonAPI.Utils
11 alias Pleroma.Web.MastodonAPI.AccountView
12 alias Pleroma.Web.MastodonAPI.StatusView
13
14 def render("index.json", %{reports: reports, for: for_user}) do
15 %{
16 reports:
17 reports[:items]
18 |> Enum.map(&Report.extract_report_info/1)
19 |> Enum.map(&render(__MODULE__, "show.json", Map.put(&1, :for, for_user))),
20 total: reports[:total]
21 }
22 end
23
24 def render("show.json", %{
25 report: report,
26 user: actor,
27 account: account,
28 statuses: statuses,
29 for: for_user
30 }) do
31 created_at = Utils.to_masto_date(report.data["published"])
32
33 content =
34 unless is_nil(report.data["content"]) do
35 HTML.filter_tags(report.data["content"])
36 else
37 nil
38 end
39
40 %{
41 id: report.id,
42 account: AccountView.render("show.json", %{user: account, for: for_user}),
43 actor: AccountView.render("show.json", %{user: actor, for: for_user}),
44 content: content,
45 created_at: created_at,
46 statuses:
47 StatusView.render("index.json", %{
48 activities: statuses,
49 as: :activity,
50 for: for_user
51 }),
52 state: report.data["state"]
53 }
54 end
55 end