Display multilang in history items

This commit is contained in:
tusooa 2023-01-01 23:37:49 -05:00 committed by marcin mikołajczak
parent 39cdde78e1
commit ad8f47fe8f
3 changed files with 57 additions and 13 deletions

View file

@ -6,6 +6,7 @@ defmodule Pleroma.Web.ApiSpec.StatusOperation do
alias OpenApiSpex.Operation
alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.AccountOperation
alias Pleroma.Web.ApiSpec.Helpers
alias Pleroma.Web.ApiSpec.Schemas.Account
alias Pleroma.Web.ApiSpec.Schemas.ApiError
alias Pleroma.Web.ApiSpec.Schemas.Attachment
@ -769,6 +770,12 @@ defp status_history_response do
format: :html,
description: "HTML-encoded status content"
},
content_map:
Helpers.multilang_map_of(%Schema{
type: :string,
format: :html,
description: "HTML-encoded status content"
}),
sensitive: %Schema{
type: :boolean,
description: "Is this status marked as sensitive content?"
@ -778,6 +785,12 @@ defp status_history_response do
description:
"Subject or summary line, below which status content is collapsed until expanded"
},
spoiler_text_map:
Helpers.multilang_map_of(%Schema{
type: :string,
description:
"Subject or summary line, below which status content is collapsed until expanded"
}),
created_at: %Schema{
type: :string,
format: "date-time",

View file

@ -359,8 +359,6 @@ def render("show.json", %{activity: %{data: %{"object" => _object}} = activity}
chrono_order: chrono_order
})
content_languages = Map.keys(content_html_map)
summary = object.data["summary"] || ""
summary_map = object.data["summaryMap"] || %{}
@ -536,19 +534,17 @@ def render(
created_at = Utils.to_masto_date(object.data["updated"] || object.data["published"])
content =
object
|> render_content()
content_html =
content
|> Activity.HTML.get_cached_scrubbed_html_for_activity(
User.html_filter_policy(opts[:for]),
activity,
"mastoapi:content:#{chrono_order}"
)
{content_html, content_html_map} =
get_content_and_map(%{
type: :html,
user: opts[:for],
activity: activity,
object: object,
chrono_order: chrono_order
})
summary = object.data["summary"] || ""
summary_map = object.data["summaryMap"] || %{}
%{
account:
@ -557,8 +553,10 @@ def render(
for: opts[:for]
}),
content: content_html,
content_map: content_html_map,
sensitive: sensitive,
spoiler_text: summary,
spoiler_text_map: summary_map,
created_at: created_at,
media_attachments: attachments,
emojis: build_emojis(object.data["emoji"]),

View file

@ -1024,4 +1024,37 @@ test "with a source string, renders source and put text/plain as the content typ
assert status.content_type == "text/plain"
end
end
describe "history items" do
test "renders multilang" do
user = insert(:user)
note_obj =
insert(:note,
data: %{
"content" => "mew mew",
"contentMap" => %{"en" => "mew mew", "cmn" => "喵喵"},
"summary" => "mew",
"summaryMap" => %{"en" => "mew", "cmn" => ""}
}
)
note = insert(:note_activity, note: note_obj, user: user)
status =
StatusView.render("history_item.json", %{
activity: note,
user: user,
hashtags: [],
item: %{object: note_obj, chrono_order: 0}
})
assert %{
content: "mew mew",
content_map: %{"en" => "mew mew", "cmn" => "喵喵"},
spoiler_text: "mew",
spoiler_text_map: %{"en" => "mew", "cmn" => ""}
} = status
end
end
end