[Pleroma.Web.TwitterAPI.UserView]: Add mastodon-fields in "fields"
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Thu, 27 Sep 2018 18:17:44 +0000 (20:17 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Fri, 28 Sep 2018 08:44:45 +0000 (10:44 +0200)
lib/pleroma/web/twitter_api/views/user_view.ex
test/web/twitter_api/views/user_view_test.exs

index cfbaef4c98527abce67946a7e2d2edff2ed555d6..a662f83b66cc0fee7605b3d73e3d9f78d68e0866 100644 (file)
@@ -37,6 +37,13 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
         {String.trim(name, ":"), url}
       end)
 
+    # ``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)
+
     data = %{
       "created_at" => user.inserted_at |> Utils.format_naive_asctime(),
       "description" => HTML.strip_tags((user.bio || "") |> String.replace("<br>", "\n")),
@@ -65,7 +72,8 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
       "is_local" => user.local,
       "locked" => !!user.info["locked"],
       "default_scope" => user.info["default_scope"] || "public",
-      "no_rich_text" => user.info["no_rich_text"] || false
+      "no_rich_text" => user.info["no_rich_text"] || false,
+      "fields" => fields
     }
 
     if assigns[:token] do
index 50687f4505808883e41c3fef1e0396893baf66fc..383d7d34cf864fdbf14e5e0dfa38d0a9233c887f 100644 (file)
@@ -88,7 +88,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "is_local" => true,
       "locked" => false,
       "default_scope" => "public",
-      "no_rich_text" => false
+      "no_rich_text" => false,
+      "fields" => []
     }
 
     assert represented == UserView.render("show.json", %{user: user})
@@ -128,7 +129,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "is_local" => true,
       "locked" => false,
       "default_scope" => "public",
-      "no_rich_text" => false
+      "no_rich_text" => false,
+      "fields" => []
     }
 
     assert represented == UserView.render("show.json", %{user: user, for: follower})
@@ -169,7 +171,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "is_local" => true,
       "locked" => false,
       "default_scope" => "public",
-      "no_rich_text" => false
+      "no_rich_text" => false,
+      "fields" => []
     }
 
     assert represented == UserView.render("show.json", %{user: follower, for: user})
@@ -217,7 +220,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
       "is_local" => true,
       "locked" => false,
       "default_scope" => "public",
-      "no_rich_text" => false
+      "no_rich_text" => false,
+      "fields" => []
     }
 
     blocker = Repo.get(User, blocker.id)