diff --git a/lib/pleroma/web/api_spec/schemas/poll.ex b/lib/pleroma/web/api_spec/schemas/poll.ex index 20cf5b061b..584bb48626 100644 --- a/lib/pleroma/web/api_spec/schemas/poll.ex +++ b/lib/pleroma/web/api_spec/schemas/poll.ex @@ -4,6 +4,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Poll do alias OpenApiSpex.Schema + alias Pleroma.Web.ApiSpec.Helpers alias Pleroma.Web.ApiSpec.Schemas.Emoji alias Pleroma.Web.ApiSpec.Schemas.FlakeID @@ -52,6 +53,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Poll do type: :object, properties: %{ title: %Schema{type: :string}, + title_map: Helpers.multilang_map_of(%Schema{type: :string}), votes_count: %Schema{type: :integer} } }, @@ -81,10 +83,12 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Poll do options: [ %{ title: "accept", + title_map: %{"en" => "accept", "cmn" => "接受"}, votes_count: 6 }, %{ title: "deny", + title_map: %{"en" => "deny", "cmn" => "拒绝"}, votes_count: 4 } ], diff --git a/lib/pleroma/web/mastodon_api/views/poll_view.ex b/lib/pleroma/web/mastodon_api/views/poll_view.ex index 5bc482c8d8..a256e3bc83 100644 --- a/lib/pleroma/web/mastodon_api/views/poll_view.ex +++ b/lib/pleroma/web/mastodon_api/views/poll_view.ex @@ -65,7 +65,8 @@ defp options_and_votes_count(options) do current_count = option["replies"]["totalItems"] || 0 {%{ - title: name, + title: option["nameRendered"] || name, + title_map: option["nameMap"] || %{}, votes_count: current_count }, current_count + count} end) diff --git a/test/pleroma/web/mastodon_api/views/poll_view_test.exs b/test/pleroma/web/mastodon_api/views/poll_view_test.exs index e3508d0757..71ecd2116e 100644 --- a/test/pleroma/web/mastodon_api/views/poll_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/poll_view_test.exs @@ -37,10 +37,10 @@ test "renders a poll" do id: to_string(object.id), multiple: false, options: [ - %{title: "absolutely!", votes_count: 0}, - %{title: "sure", votes_count: 0}, - %{title: "yes", votes_count: 0}, - %{title: "why are you even asking?", votes_count: 0} + %{title: "absolutely!", title_map: %{}, votes_count: 0}, + %{title: "sure", title_map: %{}, votes_count: 0}, + %{title: "yes", title_map: %{}, votes_count: 0}, + %{title: "why are you even asking?", title_map: %{}, votes_count: 0} ], votes_count: 0, voters_count: 0, @@ -167,6 +167,31 @@ test "doesn't strips HTML tags" do } = PollView.render("show.json", %{object: object}) end + describe "multilang" do + test "renders multilang" do + object = %Object{ + id: 123, + data: %{ + "oneOf" => [ + %{ + "name" => "mew", + "nameMap" => %{"en" => "mew", "cmn" => "喵"}, + "nameRendered" => "mew | 喵" + }, + %{"name" => "mew mew", "nameMap" => %{"en" => "mew mew", "cmn" => "喵喵"}} + ] + } + } + + assert %{ + options: [ + %{title: "mew | 喵", title_map: %{"en" => "mew", "cmn" => "喵"}}, + %{title: "mew mew", title_map: %{"en" => "mew mew", "cmn" => "喵喵"}} + ] + } = PollView.render("show.json", %{object: object}) + end + end + test "displays correct voters count" do object = Object.normalize("https://friends.grishka.me/posts/54642", fetch: true) result = PollView.render("show.json", %{object: object})