AdminAPI: Merge account views for list instance statuses
[akkoma] / lib / pleroma / web / admin_api / views / status_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.StatusView do
6 use Pleroma.Web, :view
7
8 require Pleroma.Constants
9
10 alias Pleroma.User
11
12 def render("index.json", opts) do
13 render_many(opts.activities, __MODULE__, "show.json", opts)
14 end
15
16 def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
17 user = get_user(activity.data["actor"])
18
19 Pleroma.Web.MastodonAPI.StatusView.render("show.json", opts)
20 |> Map.merge(%{account: merge_account_views(user)})
21 end
22
23 defp merge_account_views(%User{} = user) do
24 Pleroma.Web.MastodonAPI.AccountView.render("show.json", %{user: user})
25 |> Map.merge(Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user}))
26 end
27
28 defp merge_account_views(_), do: %{}
29
30 defp get_user(ap_id) do
31 cond do
32 user = User.get_cached_by_ap_id(ap_id) ->
33 user
34
35 user = User.get_by_guessed_nickname(ap_id) ->
36 user
37
38 true ->
39 User.error_user(ap_id)
40 end
41 end
42 end