Add profile custom fields to ActivityPub.UserView
authorEgor Kislitsyn <egor@kislitsyn.com>
Thu, 25 Jul 2019 12:35:34 +0000 (19:35 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Wed, 14 Aug 2019 07:52:54 +0000 (14:52 +0700)
lib/pleroma/web/activity_pub/views/user_view.ex
test/web/activity_pub/views/user_view_test.exs

index 06c9e1c7117af988ddcb86fc243c4b25cbb7f3eb..7b4bc998bfe8e21178ad6e47f0b50fedfda972f9 100644 (file)
@@ -80,6 +80,11 @@ defmodule Pleroma.Web.ActivityPub.UserView do
       |> Transmogrifier.add_emoji_tags()
       |> Map.get("tag", [])
 
+    fields =
+      user.info
+      |> User.Info.fields()
+      |> Enum.map(&Map.put(&1, "type", "PropertyValue"))
+
     %{
       "id" => user.ap_id,
       "type" => "Person",
@@ -98,6 +103,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
         "publicKeyPem" => public_key
       },
       "endpoints" => endpoints,
+      "attachment" => fields,
       "tag" => (user.info.source_data["tag"] || []) ++ user_tags
     }
     |> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
index 86254117f592a5fb7863a4e36d5ea783206b4796..48a522c6ceaa5ce3c060bd281db7a01da2d963e2 100644 (file)
@@ -22,6 +22,22 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
     assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
   end
 
+  test "Renders profile fields" do
+    fields = [
+      %{"name" => "foo", "value" => "bar"},
+      %{"name" => "website", "value" => "cofe.my"}
+    ]
+
+    user = insert(:user, info: %{fields: fields})
+
+    assert %{
+             "attachment" => [
+               %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
+               %{"name" => "website", "type" => "PropertyValue", "value" => "cofe.my"}
+             ]
+           } = UserView.render("user.json", %{user: user})
+  end
+
   test "Does not add an avatar image if the user hasn't set one" do
     user = insert(:user)
     {:ok, user} = User.ensure_keys_present(user)