Use Jason for rendering responses
[akkoma] / lib / pleroma / user / info.ex
index 47e7df911a785726661e5f4a1eec366645252097..779bfbc188a911c324d4ad006a616565c3ba2ad1 100644 (file)
@@ -49,7 +49,7 @@ defmodule Pleroma.User.Info do
     field(:mascot, :map, default: nil)
     field(:emoji, {:array, :map}, default: [])
     field(:pleroma_settings_store, :map, default: %{})
-    field(:fields, {:array, :map}, default: [])
+    field(:fields, {:array, :map}, default: nil)
     field(:raw_fields, {:array, :map}, default: [])
 
     field(:notification_settings, :map,
@@ -422,12 +422,17 @@ defmodule Pleroma.User.Info do
 
   # ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
   # For example: [{"name": "Pronoun", "value": "she/her"}, …]
-  def fields(%{fields: [], source_data: %{"attachment" => attachment}}) do
+  def fields(%{fields: nil, source_data: %{"attachment" => attachment}}) do
+    limit = Pleroma.Config.get([:instance, :max_remote_account_fields], 0)
+
     attachment
     |> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
     |> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
+    |> Enum.take(limit)
   end
 
+  def fields(%{fields: nil}), do: []
+
   def fields(%{fields: fields}), do: fields
 
   def follow_information_update(info, params) do