Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into rum-index
[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.Activity
8 alias Pleroma.User
9 alias Pleroma.Web.CommonAPI.Utils
10 alias Pleroma.Web.MastodonAPI.AccountView
11 alias Pleroma.Web.MastodonAPI.StatusView
12
13 def render("index.json", %{reports: reports}) do
14 %{
15 reports: render_many(reports, __MODULE__, "show.json", as: :report)
16 }
17 end
18
19 def render("show.json", %{report: report}) do
20 user = User.get_cached_by_ap_id(report.data["actor"])
21 created_at = Utils.to_masto_date(report.data["published"])
22
23 [account_ap_id | status_ap_ids] = report.data["object"]
24 account = User.get_cached_by_ap_id(account_ap_id)
25
26 statuses =
27 Enum.map(status_ap_ids, fn ap_id ->
28 Activity.get_by_ap_id_with_object(ap_id)
29 end)
30
31 %{
32 id: report.id,
33 account: AccountView.render("account.json", %{user: account}),
34 actor: AccountView.render("account.json", %{user: user}),
35 content: report.data["content"],
36 created_at: created_at,
37 statuses: StatusView.render("index.json", %{activities: statuses, as: :activity}),
38 state: report.data["state"]
39 }
40 end
41 end