Merge branch 'develop' into 'remove-avatar-header'
[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.HTML
9 alias Pleroma.User
10 alias Pleroma.Web.CommonAPI.Utils
11 alias Pleroma.Web.MastodonAPI.AccountView
12 alias Pleroma.Web.MastodonAPI.StatusView
13
14 def render("index.json", %{reports: reports}) do
15 %{
16 reports: render_many(reports, __MODULE__, "show.json", as: :report)
17 }
18 end
19
20 def render("show.json", %{report: report}) do
21 user = User.get_cached_by_ap_id(report.data["actor"])
22 created_at = Utils.to_masto_date(report.data["published"])
23
24 [account_ap_id | status_ap_ids] = report.data["object"]
25 account = User.get_cached_by_ap_id(account_ap_id)
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 statuses =
35 Enum.map(status_ap_ids, fn ap_id ->
36 Activity.get_by_ap_id_with_object(ap_id)
37 end)
38
39 %{
40 id: report.id,
41 account: AccountView.render("account.json", %{user: account}),
42 actor: AccountView.render("account.json", %{user: user}),
43 content: content,
44 created_at: created_at,
45 statuses: StatusView.render("index.json", %{activities: statuses, as: :activity}),
46 state: report.data["state"]
47 }
48 end
49 end