Merge branch 'exclude-reblogs-from-admin-api-by-default' into 'develop'
[akkoma] / lib / pleroma / web / activity_pub / views / object_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.ObjectView do
6 use Pleroma.Web, :view
7 alias Pleroma.Activity
8 alias Pleroma.Object
9 alias Pleroma.Web.ActivityPub.Transmogrifier
10
11 def render("object.json", %{object: %Object{} = object}) do
12 base = Pleroma.Web.ActivityPub.Utils.make_json_ld_header()
13
14 additional = Transmogrifier.prepare_object(object.data)
15 Map.merge(base, additional)
16 end
17
18 def render("object.json", %{object: %Activity{data: %{"type" => activity_type}} = activity})
19 when activity_type in ["Create", "Listen"] do
20 base = Pleroma.Web.ActivityPub.Utils.make_json_ld_header()
21 object = Object.normalize(activity)
22
23 additional =
24 Transmogrifier.prepare_object(activity.data)
25 |> Map.put("object", Transmogrifier.prepare_object(object.data))
26
27 Map.merge(base, additional)
28 end
29
30 def render("object.json", %{object: %Activity{} = activity}) do
31 base = Pleroma.Web.ActivityPub.Utils.make_json_ld_header()
32 object = Object.normalize(activity)
33
34 additional =
35 Transmogrifier.prepare_object(activity.data)
36 |> Map.put("object", object.data["id"])
37
38 Map.merge(base, additional)
39 end
40 end