diff options
author | lain <lain@soykaf.club> | 2020-06-02 14:04:34 +0000 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-06-02 14:04:34 +0000 |
commit | 2860c66e88df6746b5ede2cfecf2392abf004fd2 (patch) | |
tree | 4eaba88349782c6b3e50afefd1d82224d8f9c96f /lib/pleroma/web/embed_controller.ex | |
parent | cd2abcc0e3a67898fbadd073ff778e7342c09709 (diff) | |
parent | 6b84c62d4a51cb17192945d1b67999b2c56a23d2 (diff) | |
download | pleroma-2860c66e88df6746b5ede2cfecf2392abf004fd2.tar.gz |
Merge branch 'feature/embeddable-posts' into 'develop'
Add embeddable posts
Closes #1288
See merge request pleroma/pleroma!2319
Diffstat (limited to 'lib/pleroma/web/embed_controller.ex')
-rw-r--r-- | lib/pleroma/web/embed_controller.ex | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/pleroma/web/embed_controller.ex b/lib/pleroma/web/embed_controller.ex new file mode 100644 index 000000000..f6b8a5ee1 --- /dev/null +++ b/lib/pleroma/web/embed_controller.ex @@ -0,0 +1,42 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.EmbedController do + use Pleroma.Web, :controller + + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.User + + alias Pleroma.Web.ActivityPub.Visibility + + plug(:put_layout, :embed) + + def show(conn, %{"id" => id}) do + with %Activity{local: true} = activity <- + Activity.get_by_id_with_object(id), + true <- Visibility.is_public?(activity.object) do + {:ok, author} = User.get_or_fetch(activity.object.data["actor"]) + + conn + |> delete_resp_header("x-frame-options") + |> delete_resp_header("content-security-policy") + |> render("show.html", + activity: activity, + author: User.sanitize_html(author), + counts: get_counts(activity) + ) + end + end + + defp get_counts(%Activity{} = activity) do + %Object{data: data} = Object.normalize(activity) + + %{ + likes: Map.get(data, "like_count", 0), + replies: Map.get(data, "repliesCount", 0), + announces: Map.get(data, "announcement_count", 0) + } + end +end |