Add also_known_as field to Pleroma.User

This commit is contained in:
Egor Kislitsyn 2019-10-25 19:14:18 +07:00
parent 96cd66ac1b
commit b777083f3f
No known key found for this signature in database
GPG Key ID: 1B49CB15B71E7805
7 changed files with 61 additions and 7 deletions

View 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(:also_known_as, {:array, :string}, default: [])
field(:notification_settings, :map,
default: %{
@ -324,7 +325,8 @@ def remote_user_creation(params) do
:fields,
:following_count,
:discoverable,
:invisible
:invisible,
:also_known_as
]
)
|> validate_required([:name, :ap_id])
@ -373,7 +375,8 @@ def update_changeset(struct, params \\ %{}) do
:fields,
:raw_fields,
:pleroma_settings_store,
:discoverable
:discoverable,
:also_known_as
]
)
|> unique_constraint(:nickname)
@ -413,7 +416,8 @@ def upgrade_changeset(struct, params \\ %{}, remote? \\ false) do
:hide_followers,
:discoverable,
:hide_followers_count,
:hide_follows_count
:hide_follows_count,
:also_known_as
]
)
|> unique_constraint(:nickname)

View File

@ -1117,7 +1117,8 @@ defp object_to_user_data(data) do
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

View File

@ -616,7 +616,7 @@ def handle_incoming(
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)

View File

@ -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

View File

@ -28,6 +28,10 @@
"oauthRegistrationEndpoint": {
"@id": "litepub:oauthRegistrationEndpoint",
"@type": "@id"
},
"alsoKnownAs": {
"@id": "as:alsoKnownAs",
"@type": "@id"
}
}
]

View File

@ -9,7 +9,11 @@
"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",
@ -50,5 +54,6 @@
"type": "Image",
"mediaType": "image/png",
"url": "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
}
},
"alsoKnownAs": ["http://example.org/users/foo"]
}

View File

@ -592,6 +592,37 @@ test "it works for incoming update activities" do
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"