Fetch translations with posts

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2023-10-10 16:54:50 +02:00
parent 0af2d38e07
commit a8e974d47b
2 changed files with 23 additions and 18 deletions

View file

@ -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.")

View file

@ -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)