Typo
[akkoma] / lib / pleroma / web / admin_api / views / report_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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 alias Pleroma.HTML
8 alias Pleroma.User
9 alias Pleroma.Web.AdminAPI.Report
10 alias Pleroma.Web.CommonAPI.Utils
11 alias Pleroma.Web.MastodonAPI.StatusView
12
13 def render("index.json", %{reports: reports}) do
14 %{
15 reports:
16 reports[:items]
17 |> Enum.map(&Report.extract_report_info(&1))
18 |> Enum.map(&render(__MODULE__, "show.json", &1))
19 |> Enum.reverse(),
20 total: reports[:total]
21 }
22 end
23
24 def render("show.json", %{report: report, user: user, account: account, statuses: statuses}) do
25 created_at = Utils.to_masto_date(report.data["published"])
26
27 content =
28 unless is_nil(report.data["content"]) do
29 HTML.filter_tags(report.data["content"])
30 else
31 nil
32 end
33
34 %{
35 id: report.id,
36 account: merge_account_views(account),
37 actor: merge_account_views(user),
38 content: content,
39 created_at: created_at,
40 statuses: StatusView.render("index.json", %{activities: statuses, as: :activity}),
41 state: report.data["state"]
42 }
43 end
44
45 def render("index_grouped.json", %{groups: groups}) do
46 reports =
47 Enum.map(groups, fn group ->
48 status =
49 if group[:status_deleted],
50 do: group[:status],
51 else: StatusView.render("show.json", %{activity: group[:status]})
52
53 %{
54 date: group[:date],
55 account: group[:account],
56 status: status,
57 status_deleted: group[:status_deleted],
58 actors: Enum.map(group[:actors], &merge_account_views/1),
59 reports:
60 group[:reports]
61 |> Enum.map(&Report.extract_report_info(&1))
62 |> Enum.map(&render(__MODULE__, "show.json", &1))
63 }
64 end)
65
66 %{
67 reports: reports
68 }
69 end
70
71 defp merge_account_views(%User{} = user) do
72 Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user})
73 |> Map.merge(Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user}))
74 end
75
76 defp merge_account_views(_), do: %{}
77 end