Render language attr of a status

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
tusooa 2023-01-04 11:03:11 -05:00 committed by marcin mikołajczak
parent afab622520
commit c4cec5fd6a
2 changed files with 36 additions and 3 deletions

View file

@ -228,7 +228,7 @@ def render(
mentions: mentions,
tags: reblogged[:tags] || [],
application: build_application(object.data["generator"]),
language: get_language(object),
language: get_language(object.data),
emojis: [],
pleroma: %{
local: activity.local,
@ -999,7 +999,7 @@ defp get_content_and_map(%{
{content_und, content_map}
end
defp get_language(%{data: %{"language" => "und"}}), do: nil
defp get_language(%{"language" => "und"}), do: nil
defp get_language(object), do: object.data["language"]
defp get_language(data), do: data["language"]
end

View file

@ -380,6 +380,7 @@ test "a note activity with multiple languages" do
content_map: %{"en" => "mew mew", "cmn" => "喵喵"},
spoiler_text: "mew",
spoiler_text_map: %{"en" => "mew", "cmn" => ""},
language: "mul",
pleroma: %{
content: %{"text/plain" => "mew mew"},
content_map: %{"text/plain" => %{"en" => "mew mew", "cmn" => "喵喵"}},
@ -389,6 +390,38 @@ test "a note activity with multiple languages" do
} = status
end
test "a note activity with single language" do
user = insert(:user)
note_obj =
insert(:note,
data: %{
"content" => "mew mew",
"contentMap" => %{"en" => "mew mew"},
"summary" => "mew",
"summaryMap" => %{"en" => "mew"}
}
)
note = insert(:note_activity, note: note_obj, user: user)
status = StatusView.render("show.json", %{activity: note})
assert %{
content: "mew mew",
content_map: %{"en" => "mew mew"},
spoiler_text: "mew",
spoiler_text_map: %{"en" => "mew"},
language: "en",
pleroma: %{
content: %{"text/plain" => "mew mew"},
content_map: %{"text/plain" => %{"en" => "mew mew"}},
spoiler_text: %{"text/plain" => "mew"},
spoiler_text_map: %{"text/plain" => %{"en" => "mew"}}
}
} = status
end
test "tells if the message is muted for some reason" do
user = insert(:user)
other_user = insert(:user)