From 4f5c4d79c4534f0d9976543f718bea3edea843af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Thu, 11 Apr 2024 16:50:06 +0200 Subject: [PATCH] FEP-2c59, add "webfinger" to user actor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- changelog.d/fep-2c59.add | 1 + lib/pleroma/web/activity_pub/views/user_view.ex | 12 +++++++++--- priv/static/schemas/litepub-0.1.jsonld | 1 + .../web/activity_pub/views/user_view_test.exs | 7 +++++++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 changelog.d/fep-2c59.add diff --git a/changelog.d/fep-2c59.add b/changelog.d/fep-2c59.add new file mode 100644 index 000000000..03e33cbd8 --- /dev/null +++ b/changelog.d/fep-2c59.add @@ -0,0 +1 @@ +Implement FEP-2c59, add "webfinger" to user actor \ No newline at end of file diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 24ee683ae..937e4fd67 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -67,8 +67,13 @@ defmodule Pleroma.Web.ActivityPub.UserView do def render("user.json", %{user: %User{nickname: nil} = user}), do: render("service.json", %{user: user}) - def render("user.json", %{user: %User{nickname: "internal." <> _} = user}), - do: render("service.json", %{user: user}) |> Map.put("preferredUsername", user.nickname) + def render("user.json", %{user: %User{nickname: "internal." <> _} = user}) do + render("service.json", %{user: user}) + |> Map.merge(%{ + "preferredUsername" => user.nickname, + "webfinger" => "acct:#{User.full_nickname(user)}" + }) + end def render("user.json", %{user: user}) do {:ok, _, public_key} = Keys.keys_from_pem(user.keys) @@ -121,7 +126,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do "discoverable" => user.is_discoverable, "capabilities" => capabilities, "alsoKnownAs" => user.also_known_as, - "vcard:bday" => birthday + "vcard:bday" => birthday, + "webfinger" => "acct:#{User.full_nickname(user)}" } |> 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/priv/static/schemas/litepub-0.1.jsonld b/priv/static/schemas/litepub-0.1.jsonld index d156cba55..3569165a4 100644 --- a/priv/static/schemas/litepub-0.1.jsonld +++ b/priv/static/schemas/litepub-0.1.jsonld @@ -2,6 +2,7 @@ "@context": [ "https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1", + "https://purl.archive.org/socialweb/webfinger", { "Emoji": "toot:Emoji", "Hashtag": "as:Hashtag", diff --git a/test/pleroma/web/activity_pub/views/user_view_test.exs b/test/pleroma/web/activity_pub/views/user_view_test.exs index f9068db07..c75149dab 100644 --- a/test/pleroma/web/activity_pub/views/user_view_test.exs +++ b/test/pleroma/web/activity_pub/views/user_view_test.exs @@ -91,6 +91,13 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do assert %{"alsoKnownAs" => ^akas} = UserView.render("user.json", %{user: user}) end + test "renders full nickname" do + clear_config([Pleroma.Web.WebFinger, :domain], "plemora.dev") + + user = insert(:user, nickname: "user") + assert %{"webfinger" => "acct:user@plemora.dev"} = UserView.render("user.json", %{user: user}) + end + describe "endpoints" do test "local users have a usable endpoints structure" do user = insert(:user)