diff options
author | lain <lain@soykaf.club> | 2021-01-05 12:31:33 +0000 |
---|---|---|
committer | lain <lain@soykaf.club> | 2021-01-05 12:31:33 +0000 |
commit | 7a03b112f2ae0acbb546975a3cb57f63ab69708d (patch) | |
tree | 4444bcd2b26560d37e1e52ad6583d68c8d3f90f4 /lib | |
parent | ca7cf62d2aae25c3a299181baa3a8f389dfd1858 (diff) | |
parent | e802b48d558ccd4a65a6da2bcc6dacb057b7fd09 (diff) | |
download | pleroma-7a03b112f2ae0acbb546975a3cb57f63ab69708d.tar.gz |
Merge branch '1526-account-aliases' into 'develop'
Resolve "account move from mastodon to pleroma"
Closes #1526
See merge request pleroma/pleroma!3233
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/user.ex | 4 | ||||
-rw-r--r-- | lib/pleroma/web/activity_pub/views/user_view.ex | 3 | ||||
-rw-r--r-- | lib/pleroma/web/api_spec/operations/account_operation.ex | 7 | ||||
-rw-r--r-- | lib/pleroma/web/api_spec/schemas/account.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/mastodon_api/controllers/account_controller.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/mastodon_api/views/account_view.ex | 1 | ||||
-rw-r--r-- | lib/pleroma/web/web_finger.ex | 16 |
7 files changed, 28 insertions, 7 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index bd4801058..52730fd8d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -142,7 +142,7 @@ defmodule Pleroma.User do field(:allow_following_move, :boolean, default: true) field(:skip_thread_containment, :boolean, default: false) field(:actor_type, :string, default: "Person") - field(:also_known_as, {:array, :string}, default: []) + field(:also_known_as, {:array, ObjectValidators.ObjectID}, default: []) field(:inbox, :string) field(:shared_inbox, :string) field(:accepts_chat_messages, :boolean, default: nil) @@ -515,6 +515,7 @@ defmodule Pleroma.User do :hide_follows_count, :hide_favorites, :allow_following_move, + :also_known_as, :background, :show_role, :skip_thread_containment, @@ -523,7 +524,6 @@ defmodule Pleroma.User do :pleroma_settings_store, :is_discoverable, :actor_type, - :also_known_as, :accepts_chat_messages ] ) diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 93c9f436c..241224b57 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -112,7 +112,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do "tag" => emoji_tags, # Note: key name is indeed "discoverable" (not an error) "discoverable" => user.is_discoverable, - "capabilities" => capabilities + "capabilities" => capabilities, + "alsoKnownAs" => user.also_known_as } |> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user)) |> Map.merge(maybe_make_image(&User.banner_url/2, "image", user)) diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index 280100c3d..bd3a73c11 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -614,6 +614,12 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do nullable: true, description: "Allows automatically follow moved following accounts" }, + also_known_as: %Schema{ + type: :array, + items: %Schema{type: :string}, + nullable: true, + description: "List of alternate ActivityPub IDs" + }, pleroma_background_image: %Schema{ type: :string, nullable: true, @@ -644,6 +650,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}}, skip_thread_containment: false, allow_following_move: false, + also_known_as: ["https://foo.bar/users/foo"], discoverable: false, actor_type: "Person" } diff --git a/lib/pleroma/web/api_spec/schemas/account.ex b/lib/pleroma/web/api_spec/schemas/account.ex index 684f6fc92..70437003c 100644 --- a/lib/pleroma/web/api_spec/schemas/account.ex +++ b/lib/pleroma/web/api_spec/schemas/account.ex @@ -40,6 +40,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do pleroma: %Schema{ type: :object, properties: %{ + ap_id: %Schema{type: :string}, + also_known_as: %Schema{type: :array, items: %Schema{type: :string}}, allow_following_move: %Schema{ type: :boolean, description: "whether the user allows automatically follow moved following accounts" diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index b4375872b..3951d10ac 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -184,6 +184,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do :show_role, :skip_thread_containment, :allow_following_move, + :also_known_as, :accepts_chat_messages ] |> Enum.reduce(%{}, fn key, acc -> @@ -207,6 +208,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do if bot, do: {:ok, "Service"}, else: {:ok, "Person"} end) |> Maps.put_if_present(:actor_type, params[:actor_type]) + |> Maps.put_if_present(:also_known_as, params[:also_known_as]) # Note: param name is indeed :locked (not an error) |> Maps.put_if_present(:is_locked, params[:locked]) # Note: param name is indeed :discoverable (not an error) diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 026ae9458..948a05a6d 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -265,6 +265,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do # Pleroma extension pleroma: %{ ap_id: user.ap_id, + also_known_as: user.also_known_as, confirmation_pending: user.confirmation_pending, tags: user.tags, hide_followers_count: user.hide_followers_count, diff --git a/lib/pleroma/web/web_finger.ex b/lib/pleroma/web/web_finger.ex index 2e39ae048..a109e1acc 100644 --- a/lib/pleroma/web/web_finger.ex +++ b/lib/pleroma/web/web_finger.ex @@ -58,12 +58,16 @@ defmodule Pleroma.Web.WebFinger do ] ++ Publisher.gather_webfinger_links(user) end + defp gather_aliases(%User{} = user) do + [user.ap_id | user.also_known_as] + end + def represent_user(user, "JSON") do {:ok, user} = User.ensure_keys_present(user) %{ "subject" => "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}", - "aliases" => [user.ap_id], + "aliases" => gather_aliases(user), "links" => gather_links(user) } end @@ -71,6 +75,11 @@ defmodule Pleroma.Web.WebFinger do def represent_user(user, "XML") do {:ok, user} = User.ensure_keys_present(user) + aliases = + user + |> gather_aliases() + |> Enum.map(&{:Alias, &1}) + links = gather_links(user) |> Enum.map(fn link -> {:Link, link} end) @@ -79,9 +88,8 @@ defmodule Pleroma.Web.WebFinger do :XRD, %{xmlns: "http://docs.oasis-open.org/ns/xri/xrd-1.0"}, [ - {:Subject, "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}"}, - {:Alias, user.ap_id} - ] ++ links + {:Subject, "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}"} + ] ++ aliases ++ links } |> XmlBuilder.to_doc() end |