Add a view for the move notification
[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 defp merge_account_views(%User{} = user) do
46 Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user})
47 |> Map.merge(Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user}))
48 end
49
50 defp merge_account_views(_), do: %{}
51 end