ActivityPub: Add new 'capabilities' to user.
authorlain <lain@soykaf.club>
Mon, 6 Jul 2020 09:38:40 +0000 (11:38 +0200)
committerlain <lain@soykaf.club>
Mon, 6 Jul 2020 09:38:40 +0000 (11:38 +0200)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/views/user_view.ex
priv/static/schemas/litepub-0.1.jsonld
test/fixtures/tesla_mock/admin@mastdon.example.org.json
test/web/activity_pub/views/user_view_test.exs

index 86428b8616f400e8f08b06431a9ed6974e0d90e9..17c9d8f21653545c7fbddc568d4d9af829f7462a 100644 (file)
@@ -1224,7 +1224,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
       end)
 
     locked = data["manuallyApprovesFollowers"] || false
-    accepts_chat_messages = data["acceptsChatMessages"]
+    capabilities = data["capabilities"] || %{}
+    accepts_chat_messages = capabilities["acceptsChatMessages"]
     data = Transmogrifier.maybe_fix_user_object(data)
     discoverable = data["discoverable"] || false
     invisible = data["invisible"] || false
index d062d6230c2e8ad5c7565e8504522ca30fe72b35..3a4564912c2d1508bac155bc79b23f857c528a1d 100644 (file)
@@ -81,7 +81,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
 
     fields = Enum.map(user.fields, &Map.put(&1, "type", "PropertyValue"))
 
-    chat_message_acceptance =
+    capabilities =
       if is_boolean(user.accepts_chat_messages) do
         %{
           "acceptsChatMessages" => user.accepts_chat_messages
@@ -110,9 +110,9 @@ defmodule Pleroma.Web.ActivityPub.UserView do
       "endpoints" => endpoints,
       "attachment" => fields,
       "tag" => emoji_tags,
-      "discoverable" => user.discoverable
+      "discoverable" => user.discoverable,
+      "capabilities" => capabilities
     }
-    |> Map.merge(chat_message_acceptance)
     |> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
     |> Map.merge(maybe_make_image(&User.banner_url/2, "image", user))
     |> Map.merge(Utils.make_json_ld_header())
index c1bcad0f833cddca77ab2298f991a7e909b0a9e7..e7722cf726fe2a3b0b3fd3236c04e80808252c38 100644 (file)
@@ -13,7 +13,7 @@
             },
             "discoverable": "toot:discoverable",
             "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
-            "acceptsChatMessages": "litepub:acceptsChatMessages",
+            "capabilities": "litepub:capabilities",
             "ostatus": "http://ostatus.org#",
             "schema": "http://schema.org#",
             "toot": "http://joinmastodon.org/ns#",
index f5cf174befe40038f8bad9a9c7e4265723129aa2..a911b979a21650e3cdff58c4e2bcdc525c3859f1 100644 (file)
@@ -26,7 +26,9 @@
   "summary": "\u003cp\u003e\u003c/p\u003e",
   "url": "http://mastodon.example.org/@admin",
   "manuallyApprovesFollowers": false,
-  "acceptsChatMessages": true,
+  "capabilities": {
+    "acceptsChatMessages": true
+  },
   "publicKey": {
     "id": "http://mastodon.example.org/users/admin#main-key",
     "owner": "http://mastodon.example.org/users/admin",
index 3b4a1bcdeb1fcfdc10a1da2cea5c768b1a9a090d..98c7c9d0966ab5c60b766b9c9dbeeb9863cf60d2 100644 (file)
@@ -165,9 +165,16 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
       false_user = insert(:user, accepts_chat_messages: false)
       nil_user = insert(:user, accepts_chat_messages: nil)
 
-      assert %{"acceptsChatMessages" => true} = UserView.render("user.json", user: true_user)
-      assert %{"acceptsChatMessages" => false} = UserView.render("user.json", user: false_user)
-      refute Map.has_key?(UserView.render("user.json", user: nil_user), "acceptsChatMessages")
+      assert %{"capabilities" => %{"acceptsChatMessages" => true}} =
+               UserView.render("user.json", user: true_user)
+
+      assert %{"capabilities" => %{"acceptsChatMessages" => false}} =
+               UserView.render("user.json", user: false_user)
+
+      refute Map.has_key?(
+               UserView.render("user.json", user: nil_user)["capabilities"],
+               "acceptsChatMessages"
+             )
     end
   end
 end