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_notes.json", %{notes: notes}) when is_list(notes) do
48 Enum.map(notes, &render(__MODULE__, "show_note.json", &1))
51 def render("index_notes.json", _), do: []
53 def render("show_note.json", %{
57 inserted_at: inserted_at
59 user = User.get_by_id(user_id)
64 user: merge_account_views(user),
65 created_at: Utils.to_masto_date(inserted_at)
69 defp merge_account_views(%User{} = user) do
70 Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user})
71 |> Map.merge(Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user}))
74 defp merge_account_views(_), do: %{}