logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

report_view.ex (2003B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.AdminAPI.ReportView do
  5. use Pleroma.Web, :view
  6. alias Pleroma.HTML
  7. alias Pleroma.User
  8. alias Pleroma.Web.AdminAPI
  9. alias Pleroma.Web.AdminAPI.Report
  10. alias Pleroma.Web.CommonAPI.Utils
  11. alias Pleroma.Web.MastodonAPI.StatusView
  12. defdelegate merge_account_views(user), to: AdminAPI.AccountView
  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. total: reports[:total]
  20. }
  21. end
  22. def render("show.json", %{report: report, user: user, account: account, statuses: statuses}) do
  23. created_at = Utils.to_masto_date(report.data["published"])
  24. content =
  25. unless is_nil(report.data["content"]) do
  26. HTML.filter_tags(report.data["content"])
  27. else
  28. nil
  29. end
  30. %{
  31. id: report.id,
  32. account: merge_account_views(account),
  33. actor: merge_account_views(user),
  34. content: content,
  35. created_at: created_at,
  36. statuses:
  37. StatusView.render("index.json", %{
  38. activities: statuses,
  39. as: :activity
  40. }),
  41. state: report.data["state"],
  42. notes: render(__MODULE__, "index_notes.json", %{notes: report.report_notes})
  43. }
  44. end
  45. def render("index_notes.json", %{notes: notes}) when is_list(notes) do
  46. Enum.map(notes, &render(__MODULE__, "show_note.json", Map.from_struct(&1)))
  47. end
  48. def render("index_notes.json", _), do: []
  49. def render("show_note.json", %{
  50. id: id,
  51. content: content,
  52. user_id: user_id,
  53. inserted_at: inserted_at
  54. }) do
  55. user = User.get_by_id(user_id)
  56. %{
  57. id: id,
  58. content: content,
  59. user: merge_account_views(user),
  60. created_at: Utils.to_masto_date(inserted_at)
  61. }
  62. end
  63. end