Add `also_known_as` field to Pleroma.User
authorEgor Kislitsyn <egor@kislitsyn.com>
Fri, 25 Oct 2019 12:14:18 +0000 (19:14 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Fri, 25 Oct 2019 12:14:18 +0000 (19:14 +0700)
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
priv/repo/migrations/20191025081729_add_also_known_as_to_users.exs [new file with mode: 0644]
priv/static/schemas/litepub-0.1.jsonld
test/fixtures/tesla_mock/admin@mastdon.example.org.json
test/web/activity_pub/transmogrifier_test.exs

index 7bef6e2810c5ed08071933df8d46b9e1dc8fa157..f25345140aaca409286c2b40bbc0952b934914d2 100644 (file)
@@ -105,6 +105,7 @@ defmodule Pleroma.User do
     field(:discoverable, :boolean, default: false)
     field(:invisible, :boolean, default: false)
     field(:skip_thread_containment, :boolean, default: false)
     field(:discoverable, :boolean, default: false)
     field(:invisible, :boolean, default: false)
     field(:skip_thread_containment, :boolean, default: false)
+    field(:also_known_as, {:array, :string}, default: [])
 
     field(:notification_settings, :map,
       default: %{
 
     field(:notification_settings, :map,
       default: %{
@@ -324,7 +325,8 @@ defmodule Pleroma.User do
           :fields,
           :following_count,
           :discoverable,
           :fields,
           :following_count,
           :discoverable,
-          :invisible
+          :invisible,
+          :also_known_as
         ]
       )
       |> validate_required([:name, :ap_id])
         ]
       )
       |> validate_required([:name, :ap_id])
@@ -373,7 +375,8 @@ defmodule Pleroma.User do
         :fields,
         :raw_fields,
         :pleroma_settings_store,
         :fields,
         :raw_fields,
         :pleroma_settings_store,
-        :discoverable
+        :discoverable,
+        :also_known_as
       ]
     )
     |> unique_constraint(:nickname)
       ]
     )
     |> unique_constraint(:nickname)
@@ -413,7 +416,8 @@ defmodule Pleroma.User do
         :hide_followers,
         :discoverable,
         :hide_followers_count,
         :hide_followers,
         :discoverable,
         :hide_followers_count,
-        :hide_follows_count
+        :hide_follows_count,
+        :also_known_as
       ]
     )
     |> unique_constraint(:nickname)
       ]
     )
     |> unique_constraint(:nickname)
index 07dde35373cb407d450a5b3767a70d2739eebb2f..dc962673c2c80ae2bc7a7e0c2769a2ebe7fcb56d 100644 (file)
@@ -1117,7 +1117,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
       name: data["name"],
       follower_address: data["followers"],
       following_address: data["following"],
       name: data["name"],
       follower_address: data["followers"],
       following_address: data["following"],
-      bio: data["summary"]
+      bio: data["summary"],
+      also_known_as: Map.get(data, "alsoKnownAs", [])
     }
 
     # nickname can be nil because of virtual actors
     }
 
     # nickname can be nil because of virtual actors
index 9b3ee842ba9886b9e92845b8d0b80356597c96a1..6ada38e1ab3a6f528806d8a83aa40893a62c3237 100644 (file)
@@ -616,7 +616,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
 
       update_data =
         new_user_data
 
       update_data =
         new_user_data
-        |> Map.take([:avatar, :banner, :bio, :name])
+        |> Map.take([:avatar, :banner, :bio, :name, :also_known_as])
         |> Map.put(:fields, fields)
         |> Map.put(:locked, locked)
         |> Map.put(:invisible, invisible)
         |> Map.put(:fields, fields)
         |> Map.put(:locked, locked)
         |> Map.put(:invisible, invisible)
diff --git a/priv/repo/migrations/20191025081729_add_also_known_as_to_users.exs b/priv/repo/migrations/20191025081729_add_also_known_as_to_users.exs
new file mode 100644 (file)
index 0000000..3d9e0a3
--- /dev/null
@@ -0,0 +1,9 @@
+defmodule Pleroma.Repo.Migrations.AddAlsoKnownAsToUsers do
+  use Ecto.Migration
+
+  def change do
+    alter table(:users) do
+      add(:also_known_as, {:array, :string}, default: [])
+    end
+  end
+end
index c8e69cab5614b44fe0a3d3a7d1ee33af8e4e6a2c..509df4bb7c023875c521155613f1fc61a417a48f 100644 (file)
             "oauthRegistrationEndpoint": {
                 "@id": "litepub:oauthRegistrationEndpoint",
                 "@type": "@id"
             "oauthRegistrationEndpoint": {
                 "@id": "litepub:oauthRegistrationEndpoint",
                 "@type": "@id"
+            },
+            "alsoKnownAs": {
+                "@id": "as:alsoKnownAs",
+                "@type": "@id"
             }
         }
     ]
             }
         }
     ]
index 8159dc20ad0e3c0ba52e7e16ba2fcbc0be4ee1f8..9fdd6557ca26095df858b17b4dd7e6adf58d8aaf 100644 (file)
@@ -9,7 +9,11 @@
     "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
     "conversation": "ostatus:conversation",
     "toot": "http://joinmastodon.org/ns#",
     "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
     "conversation": "ostatus:conversation",
     "toot": "http://joinmastodon.org/ns#",
-    "Emoji": "toot:Emoji"
+    "Emoji": "toot:Emoji",
+    "alsoKnownAs": {
+      "@id": "as:alsoKnownAs",
+      "@type": "@id"
+    }
   }],
   "id": "http://mastodon.example.org/users/admin",
   "type": "Person",
   }],
   "id": "http://mastodon.example.org/users/admin",
   "type": "Person",
@@ -50,5 +54,6 @@
     "type": "Image",
     "mediaType": "image/png",
     "url": "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
     "type": "Image",
     "mediaType": "image/png",
     "url": "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
-  }
+  },
+  "alsoKnownAs": ["http://example.org/users/foo"]
 }
 }
index 6f7e1da1f65fc9eea293dd307efba4e0df3bf970..8fd2f505397e329b7522cb1916dfbf53a58f462f 100644 (file)
@@ -592,6 +592,37 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
       assert user.bio == "<p>Some bio</p>"
     end
 
       assert user.bio == "<p>Some bio</p>"
     end
 
+    test "it works with alsoKnownAs" do
+      {:ok, %Activity{data: %{"actor" => actor}}} =
+        "test/fixtures/mastodon-post-activity.json"
+        |> File.read!()
+        |> Poison.decode!()
+        |> Transmogrifier.handle_incoming()
+
+      assert User.get_cached_by_ap_id(actor).also_known_as == ["http://example.org/users/foo"]
+
+      {:ok, _activity} =
+        "test/fixtures/mastodon-update.json"
+        |> File.read!()
+        |> Poison.decode!()
+        |> Map.put("actor", actor)
+        |> Map.update!("object", fn object ->
+          object
+          |> Map.put("actor", actor)
+          |> Map.put("id", actor)
+          |> Map.put("alsoKnownAs", [
+            "http://mastodon.example.org/users/foo",
+            "http://example.org/users/bar"
+          ])
+        end)
+        |> Transmogrifier.handle_incoming()
+
+      assert User.get_cached_by_ap_id(actor).also_known_as == [
+               "http://mastodon.example.org/users/foo",
+               "http://example.org/users/bar"
+             ]
+    end
+
     test "it works with custom profile fields" do
       {:ok, activity} =
         "test/fixtures/mastodon-post-activity.json"
     test "it works with custom profile fields" do
       {:ok, activity} =
         "test/fixtures/mastodon-post-activity.json"