1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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"]
46 def render("index_grouped.json", %{groups: groups}) do
48 Enum.map(groups, fn group ->
51 %Activity{} = activity -> StatusView.render("show.json", %{activity: activity})
57 account: group[:account],
58 status: Map.put_new(status, "deleted", false),
59 actors: Enum.map(group[:actors], &merge_account_views/1),
62 |> Enum.map(&Report.extract_report_info(&1))
63 |> Enum.map(&render(__MODULE__, "show.json", &1))
72 defp merge_account_views(%User{} = user) do
73 Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user})
74 |> Map.merge(Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user}))
77 defp merge_account_views(_), do: %{}