summaryrefslogtreecommitdiff
path: root/lib/pleroma/web/pleroma_api/views/report_view.ex
blob: a0b3f085cc02848c79022b677e36975218a28ff6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.PleromaAPI.ReportView do
  use Pleroma.Web, :view

  alias Pleroma.HTML
  alias Pleroma.Web.AdminAPI.Report
  alias Pleroma.Web.CommonAPI.Utils
  alias Pleroma.Web.MastodonAPI.AccountView
  alias Pleroma.Web.MastodonAPI.StatusView

  def render("index.json", %{reports: reports, for: for_user}) do
    %{
      reports:
        reports[:items]
        |> Enum.map(&Report.extract_report_info/1)
        |> Enum.map(&render(__MODULE__, "show.json", Map.put(&1, :for, for_user))),
      total: reports[:total]
    }
  end

  def render("show.json", %{
        report: report,
        user: actor,
        account: account,
        statuses: statuses,
        for: for_user
      }) do
    created_at = Utils.to_masto_date(report.data["published"])

    content =
      unless is_nil(report.data["content"]) do
        HTML.filter_tags(report.data["content"])
      else
        nil
      end

    %{
      id: report.id,
      account: AccountView.render("show.json", %{user: account, for: for_user}),
      actor: AccountView.render("show.json", %{user: actor, for: for_user}),
      content: content,
      created_at: created_at,
      statuses:
        StatusView.render("index.json", %{
          activities: statuses,
          as: :activity,
          for: for_user
        }),
      state: report.data["state"]
    }
  end
end