Merge pull request #77 from DarkKirb/akkoma-add-twitter-preview

hopefully fix akkoma previews
This commit is contained in:
Charlotte 🦝 Delenk 2023-02-12 08:14:53 +01:00 committed by GitHub
commit d6fede1f06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 0 deletions

View file

@ -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

View file

@ -25,6 +25,7 @@
./jxl-polyfill.patch
./block-invalid-datetime-mrf.patch
./require-image-description.patch
./change-twitter-preview.patch
];
};
in