total rebase
[anni] / lib / pleroma / web / embed_controller.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.EmbedController do
6   use Pleroma.Web, :controller
7
8   alias Pleroma.Activity
9   alias Pleroma.Object
10   alias Pleroma.User
11
12   alias Pleroma.Web.ActivityPub.Visibility
13
14   def show(conn, %{"id" => id}) do
15     with %Activity{local: true} = activity <-
16            Activity.get_by_id_with_object(id),
17          true <- Visibility.public?(activity.object) do
18       {:ok, author} = User.get_or_fetch(activity.object.data["actor"])
19
20       conn
21       |> delete_resp_header("x-frame-options")
22       |> delete_resp_header("content-security-policy")
23       |> render("show.html",
24         activity: activity,
25         author: User.sanitize_html(author),
26         counts: get_counts(activity)
27       )
28     end
29   end
30
31   defp get_counts(%Activity{} = activity) do
32     %Object{data: data} = Object.normalize(activity, fetch: false)
33
34     %{
35       likes: Map.get(data, "like_count", 0),
36       replies: Map.get(data, "repliesCount", 0),
37       announces: Map.get(data, "announcement_count", 0)
38     }
39   end
40 end