From 818d9f7b636e8de996f1656eb9bc2f3100889257 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Thu, 4 Apr 2024 14:26:55 +0200 Subject: [PATCH 1/3] Include image description in status media cards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- changelog.d/card-image-description.add | 1 + lib/pleroma/web/api_spec/schemas/status.ex | 4 ++++ lib/pleroma/web/mastodon_api/views/status_view.ex | 1 + 3 files changed, 6 insertions(+) create mode 100644 changelog.d/card-image-description.add diff --git a/changelog.d/card-image-description.add b/changelog.d/card-image-description.add new file mode 100644 index 000000000..bf423ebb8 --- /dev/null +++ b/changelog.d/card-image-description.add @@ -0,0 +1 @@ +Include image description in status media cards \ No newline at end of file diff --git a/lib/pleroma/web/api_spec/schemas/status.ex b/lib/pleroma/web/api_spec/schemas/status.ex index a4052803b..6e537b5da 100644 --- a/lib/pleroma/web/api_spec/schemas/status.ex +++ b/lib/pleroma/web/api_spec/schemas/status.ex @@ -58,6 +58,10 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do format: :uri, description: "Preview thumbnail" }, + image_description: %Schema{ + type: :string, + description: "Alternate text that describes what is in the thumbnail" + }, title: %Schema{type: :string, description: "Title of linked resource"}, description: %Schema{type: :string, description: "Description of preview"} } diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 77af69eef..c945290c1 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -583,6 +583,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do provider_url: page_url_data.scheme <> "://" <> page_url_data.host, url: page_url, image: image_url, + image_description: rich_media["image:alt"] || "", title: rich_media["title"] || "", description: rich_media["description"] || "", pleroma: %{ From 5e7f4f687e55813059176d6046ac32c35e0e0738 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 8 May 2024 13:52:25 -0400 Subject: [PATCH 2/3] Improve StatusView tests for Cards --- test/pleroma/web/mastodon_api/views/status_view_test.exs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index 663610442..c1313eb1b 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -738,7 +738,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do {:ok, card} = Card.create(page_url, %{image: page_url <> "/example.jpg", title: "Example website"}) - %{provider_name: "example.com"} = StatusView.render("card.json", card) + assert match?(%{provider_name: "example.com"}, StatusView.render("card.json", card)) end test "a rich media card without a site name or image renders correctly" do @@ -751,7 +751,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do {:ok, card} = Card.create(page_url, fields) - %{provider_name: "example.com"} = StatusView.render("card.json", card) + assert match?(%{provider_name: "example.com"}, StatusView.render("card.json", card)) end test "a rich media card without an image renders correctly" do @@ -765,7 +765,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do {:ok, card} = Card.create(page_url, fields) - %{provider_name: "example.com"} = StatusView.render("card.json", card) + assert match?(%{provider_name: "example.com"}, StatusView.render("card.json", card)) end test "a rich media card with all relevant data renders correctly" do @@ -781,7 +781,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do {:ok, card} = Card.create(page_url, fields) - %{provider_name: "example.com"} = StatusView.render("card.json", card) + assert match?(%{provider_name: "example.com"}, StatusView.render("card.json", card)) end test "a rich media card has all media proxied" do From ccceb41bf3f50ce914c16c2a18ec882e97309214 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 8 May 2024 13:54:57 -0400 Subject: [PATCH 3/3] Add test for StatusView rendering of Cards when missing descriptions --- .../web/mastodon_api/views/status_view_test.exs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index c1313eb1b..1c2d7f7fd 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -768,6 +768,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do assert match?(%{provider_name: "example.com"}, StatusView.render("card.json", card)) end + test "a rich media card without descriptions returns the fields with empty strings" do + page_url = "https://example.com" + + fields = %{ + "url" => page_url, + "site_name" => "Example site name", + "title" => "Example website" + } + + {:ok, card} = Card.create(page_url, fields) + + assert match?( + %{description: "", image_description: ""}, + StatusView.render("card.json", card) + ) + end + test "a rich media card with all relevant data renders correctly" do page_url = "https://example.com"