Language code on mastoapi statuses (#433)
[akkoma] / lib / pleroma / web / mastodon_api / views / status_view.ex
index cc58f803e6b2c7773c96f6b1ad21d7ce0f7830ee..48756e78b6cb26f490ef3efb901c225d3dda89dd 100644 (file)
@@ -131,7 +131,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       |> Map.put(:parent_activities, parent_activities)
       |> Map.put(:relationships, relationships_opt)
 
-    safe_render_many(activities, StatusView, "show.json", opts)
+    render_many(activities, StatusView, "show.json", opts)
   end
 
   def render(
@@ -169,6 +169,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       |> Enum.map(fn user -> AccountView.render("mention.json", %{user: user}) end)
 
     {pinned?, pinned_at} = pin_data(object, user)
+    lang = language(object)
 
     %{
       id: to_string(activity.id),
@@ -199,7 +200,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       mentions: mentions,
       tags: reblogged[:tags] || [],
       application: build_application(object.data["generator"]),
-      language: nil,
+      language: lang,
       emojis: [],
       pleroma: %{
         local: activity.local,
@@ -357,6 +358,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       {pinned?, pinned_at} = pin_data(object, user)
 
       quote = Activity.get_quoted_activity_from_object(object)
+      lang = language(object)
 
       %{
         id: to_string(activity.id),
@@ -391,7 +393,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
         mentions: mentions,
         tags: build_tags(tags),
         application: build_application(object.data["generator"]),
-        language: nil,
+        language: lang,
         emojis: build_emojis(object.data["emoji"]),
         quote_id: if(quote, do: quote.id, else: nil),
         quote: maybe_render_quote(quote, opts),
@@ -784,4 +786,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
   defp get_source_content_type(_source) do
     Utils.get_content_type(nil)
   end
+
+  defp language(%Object{data: %{"contentMap" => contentMap}}) when is_map(contentMap) do
+    contentMap
+    |> Map.keys()
+    |> Enum.at(0)
+  end
+
+  defp language(_), do: nil
 end