Add metadata provider for ActivityPub alternate links
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
639016bdee
commit
60ec42cb9c
4 changed files with 55 additions and 0 deletions
1
changelog.d/activity-pub-metadata.add
Normal file
1
changelog.d/activity-pub-metadata.add
Normal file
|
@ -0,0 +1 @@
|
|||
Add metadata provider for ActivityPub alternate links
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.Metadata do
|
|||
|
||||
def build_tags(params) do
|
||||
providers = [
|
||||
Pleroma.Web.Metadata.Providers.ActivityPub,
|
||||
Pleroma.Web.Metadata.Providers.RelMe,
|
||||
Pleroma.Web.Metadata.Providers.RestrictIndexing
|
||||
| activated_providers()
|
||||
|
|
19
lib/pleroma/web/metadata/providers/activity_pub.ex
Normal file
19
lib/pleroma/web/metadata/providers/activity_pub.ex
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Metadata.Providers.ActivityPub do
|
||||
alias Pleroma.Web.Metadata.Providers.Provider
|
||||
|
||||
@behaviour Provider
|
||||
|
||||
@impl Provider
|
||||
def build_tags(%{object: %{data: %{"id" => object_id}}}) do
|
||||
[{:link, [rel: "alternate", type: "application/activity+json", href: object_id], []}]
|
||||
end
|
||||
|
||||
@impl Provider
|
||||
def build_tags(%{user: user}) do
|
||||
[{:link, [rel: "alternate", type: "application/activity+json", href: user.ap_id], []}]
|
||||
end
|
||||
end
|
34
test/pleroma/web/metadata/providers/activity_pub_test.exs
Normal file
34
test/pleroma/web/metadata/providers/activity_pub_test.exs
Normal file
|
@ -0,0 +1,34 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Metadata.Providers.ActivityPubTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Metadata.Providers.ActivityPub
|
||||
|
||||
setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
|
||||
|
||||
test "it renders a link for user info" do
|
||||
user = insert(:user)
|
||||
res = ActivityPub.build_tags(%{user: user})
|
||||
|
||||
assert res == [
|
||||
{:link, [rel: "alternate", type: "application/activity+json", href: user.ap_id], []}
|
||||
]
|
||||
end
|
||||
|
||||
test "it renders a link for a post" do
|
||||
user = insert(:user)
|
||||
{:ok, %{id: activity_id, object: object}} = CommonAPI.post(user, %{status: "hi"})
|
||||
|
||||
result = ActivityPub.build_tags(%{object: object, user: user, activity_id: activity_id})
|
||||
|
||||
assert [
|
||||
{:link,
|
||||
[rel: "alternate", type: "application/activity+json", href: object.data["id"]], []}
|
||||
] == result
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue