diff --git a/lib/pleroma/web/api_spec/schemas/attachment.ex b/lib/pleroma/web/api_spec/schemas/attachment.ex index 2871b5f999..61712c079c 100644 --- a/lib/pleroma/web/api_spec/schemas/attachment.ex +++ b/lib/pleroma/web/api_spec/schemas/attachment.ex @@ -4,6 +4,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Attachment do alias OpenApiSpex.Schema + alias Pleroma.Web.ApiSpec.Helpers require OpenApiSpex @@ -42,6 +43,13 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Attachment do description: "Alternate text that describes what is in the media attachment, to be used for the visually impaired or when media attachments do not load" }, + description_map: + Helpers.multilang_map_of(%Schema{ + type: :string, + nullable: true, + description: + "Alternate text that describes what is in the media attachment, to be used for the visually impaired or when media attachments do not load" + }), type: %Schema{ type: :string, enum: ["image", "video", "audio", "unknown"], @@ -62,6 +70,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Attachment do preview_url: "someurl", text_url: "someurl", description: nil, + description_map: %{}, pleroma: %{mime_type: "image/png"} } }) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 64f9383333..a54d6a01f1 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -644,6 +644,7 @@ def render("attachment.json", %{attachment: attachment}) do text_url: href, type: type, description: attachment["name"], + description_map: attachment["nameMap"] || %{}, pleroma: %{mime_type: media_type}, blurhash: attachment["blurhash"] } 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 d4a57bea2d..39130988d7 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -654,7 +654,8 @@ test "attachments" do description: nil, pleroma: %{mime_type: "image/png"}, meta: %{original: %{width: 200, height: 100, aspect: 2}}, - blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn" + blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn", + description_map: %{} } api_spec = Pleroma.Web.ApiSpec.spec() @@ -670,6 +671,27 @@ test "attachments" do assert_schema(result, "Attachment", api_spec) end + test "attachments with multilang" do + object = %{ + "type" => "Image", + "url" => [ + %{ + "mediaType" => "image/png", + "href" => "someurl", + "width" => 200, + "height" => 100 + } + ], + "name" => "mew mew", + "nameMap" => %{"en" => "mew mew", "cmn" => "喵喵"}, + "blurhash" => "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn", + "uuid" => 6 + } + + assert %{description: "mew mew", description_map: %{"en" => "mew mew", "cmn" => "喵喵"}} = + StatusView.render("attachment.json", %{attachment: object}) + end + test "put the url advertised in the Activity in to the url attribute" do id = "https://wedistribute.org/wp-json/pterotype/v1/object/85810" [activity] = Activity.search(nil, id)