From aa1d9815299616fad3df35b7b35d492a7d1c6f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charlotte=20=F0=9F=A6=9D=20Delenk?= Date: Sat, 11 Feb 2023 22:05:24 +0100 Subject: [PATCH] hopefully fix akkoma previews --- akkoma/change-twitter-preview.patch | 57 +++++++++++++++++++++++++++++ akkoma/default.nix | 1 + 2 files changed, 58 insertions(+) create mode 100644 akkoma/change-twitter-preview.patch diff --git a/akkoma/change-twitter-preview.patch b/akkoma/change-twitter-preview.patch new file mode 100644 index 0000000..60bea70 --- /dev/null +++ b/akkoma/change-twitter-preview.patch @@ -0,0 +1,57 @@ +diff --git a/lib/pleroma/web/metadata/providers/twitter_card.ex b/lib/pleroma/web/metadata/providers/twitter_card.ex +index 79183df86..563a18bd0 100644 +--- a/lib/pleroma/web/metadata/providers/twitter_card.ex ++++ b/lib/pleroma/web/metadata/providers/twitter_card.ex +@@ -14,8 +14,12 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do + @media_types ["image", "audio", "video"] + + @impl Provider +- def build_tags(%{activity_id: id, object: object, user: user}) do +- attachments = build_attachments(id, object) ++ def build_tags(%{ ++ object: object, ++ url: url, ++ user: user ++ }) do ++ attachments = build_attachments(object) + scrubbed_content = Utils.scrub_html_and_truncate(object) + + [ +@@ -53,7 +57,7 @@ def image_tag(user) do + []} + end + +- defp build_attachments(id, %{data: %{"attachment" => attachments}}) do ++ defp build_attachments(%{data: %{"attachment" => attachments}}) do + Enum.reduce(attachments, [], fn attachment, acc -> + rendered_tags = + Enum.reduce(attachment["url"], [], fn url, acc -> +@@ -63,7 +67,7 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) do + {:meta, [property: "twitter:card", content: "player"], []}, + {:meta, [property: "twitter:player:width", content: "480"], []}, + {:meta, [property: "twitter:player:height", content: "80"], []}, +- {:meta, [property: "twitter:player", content: player_url(id)], []} ++ {:meta, [property: "twitter:player", content: MediaProxy.url(url["href"])], []} + | acc + ] + +@@ -91,7 +95,7 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) do + + [ + {:meta, [property: "twitter:card", content: "player"], []}, +- {:meta, [property: "twitter:player", content: player_url(id)], []}, ++ {:meta, [property: "twitter:player", content: MediaProxy.url(url["href"])], []}, + {:meta, [property: "twitter:player:width", content: "#{width}"], []}, + {:meta, [property: "twitter:player:height", content: "#{height}"], []}, + {:meta, [property: "twitter:player:stream", content: MediaProxy.url(url["href"])], +@@ -112,10 +116,6 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) do + + defp build_attachments(_id, _object), do: [] + +- defp player_url(id) do +- Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice_player, id) +- end +- + # Videos have problems without dimensions, but we used to not provide WxH for images. + # A default (read: incorrect) fallback for images is likely to cause rendering bugs. + defp maybe_add_dimensions(metadata, url) do diff --git a/akkoma/default.nix b/akkoma/default.nix index 50c67cd..a4fe82c 100644 --- a/akkoma/default.nix +++ b/akkoma/default.nix @@ -25,6 +25,7 @@ ./jxl-polyfill.patch ./block-invalid-datetime-mrf.patch ./require-image-description.patch + ./change-twitter-preview.patch ]; }; in