First
[anni] / lib / pleroma / web / admin_api / report.ex
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
5 defmodule Pleroma.Web.AdminAPI.Report do
6   alias Pleroma.Activity
7   alias Pleroma.Object
8   alias Pleroma.User
9
10   def extract_report_info(
11         %{data: %{"actor" => actor, "object" => [account_ap_id | status_ap_ids]}} = report
12       ) do
13     user = User.get_cached_by_ap_id(actor)
14     account = User.get_cached_by_ap_id(account_ap_id)
15
16     statuses =
17       status_ap_ids
18       |> Enum.reject(&is_nil(&1))
19       |> Enum.map(fn
20         act when is_map(act) ->
21           Activity.get_create_by_object_ap_id_with_object(act["id"]) ||
22             Activity.get_by_ap_id_with_object(act["id"]) || make_fake_activity(act, user)
23
24         act when is_binary(act) ->
25           Activity.get_create_by_object_ap_id_with_object(act) ||
26             Activity.get_by_ap_id_with_object(act)
27       end)
28
29     %{report: report, user: user, account: account, statuses: statuses}
30   end
31
32   defp make_fake_activity(act, user) do
33     %Activity{
34       id: "pleroma:fake:#{act["id"]}",
35       data: %{
36         "actor" => user.ap_id,
37         "type" => "Create",
38         "to" => [],
39         "cc" => [],
40         "object" => act["id"],
41         "published" => act["published"],
42         "id" => act["id"],
43         "context" => "pleroma:fake"
44       },
45       recipients: [user.ap_id],
46       object: %Object{
47         data: %{
48           "actor" => user.ap_id,
49           "type" => "Note",
50           "content" => act["content"],
51           "published" => act["published"],
52           "to" => [],
53           "cc" => [],
54           "id" => act["id"],
55           "context" => "pleroma:fake"
56         }
57       }
58     }
59   end
60 end