Use info.fields instead of source_data for remote users
[akkoma] / lib / pleroma / web / twitter_api / views / user_view.ex
index f0a4ddbd3be1964eeb2116682bb20e87da4387d5..8a7d2fc72832b5a61a8394b8e8f6aac0071dd055 100644 (file)
@@ -74,12 +74,15 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
       |> HTML.filter_tags(User.html_filter_policy(for_user))
       |> Formatter.emojify(emoji)
 
-    # ``fields`` is an array of mastodon profile field, containing ``{"name": "…", "value": "…"}``.
-    # For example: [{"name": "Pronoun", "value": "she/her"}, …]
     fields =
-      (user.info.source_data["attachment"] || [])
-      |> Enum.filter(fn %{"type" => t} -> t == "PropertyValue" end)
-      |> Enum.map(fn fields -> Map.take(fields, ["name", "value"]) end)
+      user.info
+      |> User.Info.fields()
+      |> Enum.map(fn %{"name" => name, "value" => value} ->
+        %{
+          "name" => Pleroma.HTML.strip_tags(name),
+          "value" => Pleroma.HTML.filter_tags(value, Pleroma.HTML.Scrubber.LinksOnly)
+        }
+      end)
 
     data =
       %{
@@ -118,9 +121,11 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
         "pleroma" =>
           %{
             "confirmation_pending" => user_info.confirmation_pending,
-            "tags" => user.tags
+            "tags" => user.tags,
+            "skip_thread_containment" => user.info.skip_thread_containment
           }
           |> maybe_with_activation_status(user, for_user)
+          |> with_notification_settings(user, for_user)
       }
       |> maybe_with_user_settings(user, for_user)
       |> maybe_with_role(user, for_user)
@@ -132,6 +137,12 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
     end
   end
 
+  defp with_notification_settings(data, %User{id: user_id} = user, %User{id: user_id}) do
+    Map.put(data, "notification_settings", user.info.notification_settings)
+  end
+
+  defp with_notification_settings(data, _, _), do: data
+
   defp maybe_with_activation_status(data, user, %User{info: %{is_admin: true}}) do
     Map.put(data, "deactivated", user.info.deactivated)
   end