1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.AdminAPI.ReportView do
10 alias Pleroma.Web.AdminAPI.Report
11 alias Pleroma.Web.CommonAPI.Utils
12 alias Pleroma.Web.MastodonAPI.StatusView
14 def render("index.json", %{reports: reports}) do
18 |> Enum.map(&Report.extract_report_info(&1))
19 |> Enum.map(&render(__MODULE__, "show.json", &1))
21 total: reports[:total]
25 def render("show.json", %{report: report, user: user, account: account, statuses: statuses}) do
26 created_at = Utils.to_masto_date(report.data["published"])
29 unless is_nil(report.data["content"]) do
30 HTML.filter_tags(report.data["content"])
37 account: merge_account_views(account),
38 actor: merge_account_views(user),
40 created_at: created_at,
41 statuses: StatusView.render("index.json", %{activities: statuses, as: :activity}),
42 state: report.data["state"],
43 notes: render(__MODULE__, "index_notes.json", %{notes: report.report_notes})
47 def render("index_grouped.json", %{groups: groups}) do
49 Enum.map(groups, fn group ->
52 %Activity{} = activity -> StatusView.render("show.json", %{activity: activity})
58 account: group[:account],
59 status: Map.put_new(status, "deleted", false),
60 actors: Enum.map(group[:actors], &merge_account_views/1),
63 |> Enum.map(&Report.extract_report_info(&1))
64 |> Enum.map(&render(__MODULE__, "show.json", &1))
73 def render("index_notes.json", %{notes: notes}) when is_list(notes) do
74 Enum.map(notes, &render(__MODULE__, "show_note.json", &1))
77 def render("index_notes.json", _), do: []
79 def render("show_note.json", %{
83 inserted_at: inserted_at
85 user = User.get_by_id(user_id)
90 user: merge_account_views(user),
91 created_at: Utils.to_masto_date(inserted_at)
95 defp merge_account_views(%User{} = user) do
96 Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user})
97 |> Map.merge(Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user}))
100 defp merge_account_views(_), do: %{}