ActivityPub: Ingest information about chat acceptance.
authorlain <lain@soykaf.club>
Fri, 3 Jul 2020 11:58:34 +0000 (13:58 +0200)
committerlain <lain@soykaf.club>
Fri, 3 Jul 2020 11:58:34 +0000 (13:58 +0200)
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
test/fixtures/tesla_mock/admin@mastdon.example.org.json
test/web/activity_pub/activity_pub_test.exs

index 7a684b1924aa3e7864fe57a097913200a3d70753..a4130c89ff85146a8e1051cea507ab43d7d6d2b3 100644 (file)
@@ -437,7 +437,8 @@ defmodule Pleroma.User do
         :discoverable,
         :invisible,
         :actor_type,
-        :also_known_as
+        :also_known_as,
+        :accepts_chat_messages
       ]
     )
     |> validate_required([:name, :ap_id])
index 94117202c25a003d6db769b2be48c159e9a17d56..86428b8616f400e8f08b06431a9ed6974e0d90e9 100644 (file)
@@ -1224,6 +1224,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
       end)
 
     locked = data["manuallyApprovesFollowers"] || false
+    accepts_chat_messages = data["acceptsChatMessages"]
     data = Transmogrifier.maybe_fix_user_object(data)
     discoverable = data["discoverable"] || false
     invisible = data["invisible"] || false
@@ -1262,7 +1263,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
       also_known_as: Map.get(data, "alsoKnownAs", []),
       public_key: public_key,
       inbox: data["inbox"],
-      shared_inbox: shared_inbox
+      shared_inbox: shared_inbox,
+      accepts_chat_messages: accepts_chat_messages
     }
 
     # nickname can be nil because of virtual actors
index 9fdd6557ca26095df858b17b4dd7e6adf58d8aaf..f5cf174befe40038f8bad9a9c7e4265723129aa2 100644 (file)
@@ -26,6 +26,7 @@
   "summary": "\u003cp\u003e\u003c/p\u003e",
   "url": "http://mastodon.example.org/@admin",
   "manuallyApprovesFollowers": false,
+  "acceptsChatMessages": true,
   "publicKey": {
     "id": "http://mastodon.example.org/users/admin#main-key",
     "owner": "http://mastodon.example.org/users/admin",
index 575e0c5db0b6b19b3acebc3d85500b6b365c00b5..ef69f3d91e4c04fce8af194dbfd7ed89eda2598b 100644 (file)
@@ -184,36 +184,43 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       assert User.invisible?(user)
     end
 
-    test "it fetches the appropriate tag-restricted posts" do
-      user = insert(:user)
+    test "it returns a user that accepts chat messages" do
+      user_id = "http://mastodon.example.org/users/admin"
+      {:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
 
-      {:ok, status_one} = CommonAPI.post(user, %{status: ". #test"})
-      {:ok, status_two} = CommonAPI.post(user, %{status: ". #essais"})
-      {:ok, status_three} = CommonAPI.post(user, %{status: ". #test #reject"})
+      assert user.accepts_chat_messages
+    end
+  end
 
-      fetch_one = ActivityPub.fetch_activities([], %{type: "Create", tag: "test"})
+  test "it fetches the appropriate tag-restricted posts" do
+    user = insert(:user)
 
-      fetch_two = ActivityPub.fetch_activities([], %{type: "Create", tag: ["test", "essais"]})
+    {:ok, status_one} = CommonAPI.post(user, %{status: ". #test"})
+    {:ok, status_two} = CommonAPI.post(user, %{status: ". #essais"})
+    {:ok, status_three} = CommonAPI.post(user, %{status: ". #test #reject"})
 
-      fetch_three =
-        ActivityPub.fetch_activities([], %{
-          type: "Create",
-          tag: ["test", "essais"],
-          tag_reject: ["reject"]
-        })
+    fetch_one = ActivityPub.fetch_activities([], %{type: "Create", tag: "test"})
 
-      fetch_four =
-        ActivityPub.fetch_activities([], %{
-          type: "Create",
-          tag: ["test"],
-          tag_all: ["test", "reject"]
-        })
+    fetch_two = ActivityPub.fetch_activities([], %{type: "Create", tag: ["test", "essais"]})
 
-      assert fetch_one == [status_one, status_three]
-      assert fetch_two == [status_one, status_two, status_three]
-      assert fetch_three == [status_one, status_two]
-      assert fetch_four == [status_three]
-    end
+    fetch_three =
+      ActivityPub.fetch_activities([], %{
+        type: "Create",
+        tag: ["test", "essais"],
+        tag_reject: ["reject"]
+      })
+
+    fetch_four =
+      ActivityPub.fetch_activities([], %{
+        type: "Create",
+        tag: ["test"],
+        tag_all: ["test", "reject"]
+      })
+
+    assert fetch_one == [status_one, status_three]
+    assert fetch_two == [status_one, status_two, status_three]
+    assert fetch_three == [status_one, status_two]
+    assert fetch_four == [status_three]
   end
 
   describe "insertion" do