From a8e974d47b6c88cded1d20726df33b56e3f8e5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Tue, 10 Oct 2023 16:54:50 +0200 Subject: [PATCH] Fetch translations with posts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../controllers/timeline_controller.ex | 15 +++++++---- .../web/mastodon_api/views/status_view.ex | 26 +++++++++---------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex index d1ea612b11..31c6854b05 100644 --- a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex @@ -64,7 +64,8 @@ def home(%{assigns: %{user: user}} = conn, params) do activities: activities, for: user, as: :activity, - with_muted: Map.get(params, :with_muted, false) + with_muted: Map.get(params, :with_muted, false), + language: params[:language] ) end @@ -87,7 +88,8 @@ def direct(%{assigns: %{user: user}} = conn, params) do |> render("index.json", activities: activities, for: user, - as: :activity + as: :activity, + language: params[:language] ) end @@ -125,7 +127,8 @@ def public(%{assigns: %{user: user}} = conn, params) do activities: activities, for: user, as: :activity, - with_muted: Map.get(params, :with_muted, false) + with_muted: Map.get(params, :with_muted, false), + language: params[:language] ) end end @@ -172,7 +175,8 @@ def hashtag(%{assigns: %{user: user}} = conn, params) do activities: activities, for: user, as: :activity, - with_muted: Map.get(params, :with_muted, false) + with_muted: Map.get(params, :with_muted, false), + language: params[:language] ) end end @@ -206,7 +210,8 @@ def list(%{assigns: %{user: user}} = conn, %{list_id: id} = params) do activities: activities, for: user, as: :activity, - with_muted: Map.get(params, :with_muted, false) + with_muted: Map.get(params, :with_muted, false), + language: params[:language] ) else _e -> render_error(conn, :forbidden, "Error.") diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index d2ee5c6020..2beb168a39 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -482,19 +482,6 @@ def render("show.json", _) do nil end - defp get_translation(object, language) when is_binary(language) do - with true <- is_binary(object.data["language"]), - true <- object.data["language"] !== language, - %StatusTranslation{} = translation <- - StatusTranslation.get(object, language, fetch: false) do - render("translation.json", %{result: translation}) - else - _ -> nil - end - end - - defp get_translation(_, _), do: nil - def render("history.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do object = Object.normalize(activity, fetch: false) @@ -719,6 +706,19 @@ def render("translation.json", %{ %{content: content, detected_source_language: detected_source_language, provider: provider} end + defp get_translation(object, language) when is_binary(language) do + with true <- is_binary(object.data["language"]), + true <- object.data["language"] !== language, + %StatusTranslation{} = translation <- + StatusTranslation.get(object, language, fetch: false) do + render("translation.json", %{result: translation}) + else + _ -> nil + end + end + + defp get_translation(_, _), do: nil + def get_reply_to(activity, %{replied_to_activities: replied_to_activities}) do object = Object.normalize(activity, fetch: false)