Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.EmbedController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.Activity
  7. alias Pleroma.Object
  8. alias Pleroma.User
  9. alias Pleroma.Web.ActivityPub.Visibility
  10. plug(:put_layout, :embed)
  11. def show(conn, %{"id" => id}) do
  12. with %Activity{local: true} = activity <-
  13. Activity.get_by_id_with_object(id),
  14. true <- Visibility.is_public?(activity.object) do
  15. {:ok, author} = User.get_or_fetch(activity.object.data["actor"])
  16. conn
  17. |> delete_resp_header("x-frame-options")
  18. |> delete_resp_header("content-security-policy")
  19. |> render("show.html",
  20. activity: activity,
  21. author: User.sanitize_html(author),
  22. counts: get_counts(activity)
  23. )
  24. end
  25. end
  26. defp get_counts(%Activity{} = activity) do
  27. %Object{data: data} = Object.normalize(activity, fetch: false)
  28. %{
  29. likes: Map.get(data, "like_count", 0),
  30. replies: Map.get(data, "repliesCount", 0),
  31. announces: Map.get(data, "announcement_count", 0)
  32. }
  33. end
  34. end