Add mrf to force link tag of quoting posts
This commit is contained in:
parent
479a6f11db
commit
e349e92a44
@ -161,6 +161,7 @@ To add configuration to your config file, you can copy it from the base config.
|
||||
* `Pleroma.Web.ActivityPub.MRF.KeywordPolicy`: Rejects or removes from the federated timeline or replaces keywords. (See [`:mrf_keyword`](#mrf_keyword)).
|
||||
* `Pleroma.Web.ActivityPub.MRF.ForceMentionsInContent`: Forces every mentioned user to be reflected in the post content.
|
||||
* `Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy`: Forces quote post URLs to be reflected in the message content inline.
|
||||
* `Pleroma.Web.ActivityPub.MRF.QuoteToLinkTagPolicy`: Force a Link tag for posts quoting another post. (may break outgoing federation of quote posts with older Pleroma versions)
|
||||
* `transparency`: Make the content of your Message Rewrite Facility settings public (via nodeinfo).
|
||||
* `transparency_exclusions`: Exclude specific instance names from MRF transparency. The use of the exclusions feature will be disclosed in nodeinfo as a boolean value.
|
||||
|
||||
|
@ -84,6 +84,10 @@ defmodule Pleroma.Constants do
|
||||
|
||||
const(upload_object_types, do: ["Document", "Image"])
|
||||
|
||||
const(activity_json_canonical_mime_type,
|
||||
do: "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||
)
|
||||
|
||||
const(activity_json_mime_types,
|
||||
do: [
|
||||
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
|
||||
|
49
lib/pleroma/web/activity_pub/mrf/quote_to_link_tag_policy.ex
Normal file
49
lib/pleroma/web/activity_pub/mrf/quote_to_link_tag_policy.ex
Normal file
@ -0,0 +1,49 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.QuoteToLinkTagPolicy do
|
||||
@moduledoc "Force a Link tag for posts quoting another post. (may break outgoing federation of quote posts with older Pleroma versions)"
|
||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
@impl Pleroma.Web.ActivityPub.MRF.Policy
|
||||
def filter(%{"object" => %{"quoteUrl" => _} = object} = activity) do
|
||||
{:ok, Map.put(activity, "object", filter_object(object))}
|
||||
end
|
||||
|
||||
@impl Pleroma.Web.ActivityPub.MRF.Policy
|
||||
def filter(object), do: {:ok, object}
|
||||
|
||||
@impl Pleroma.Web.ActivityPub.MRF.Policy
|
||||
def describe, do: {:ok, %{}}
|
||||
|
||||
@impl Pleroma.Web.ActivityPub.MRF.Policy
|
||||
def history_awareness, do: :auto
|
||||
|
||||
defp filter_object(%{"quoteUrl" => quote_url} = object) do
|
||||
tags = object["tag"] || []
|
||||
|
||||
if Enum.any?(tags, fn tag ->
|
||||
CommonFixes.is_object_link_tag(tag) and tag["href"] == quote_url
|
||||
end) do
|
||||
object
|
||||
else
|
||||
object
|
||||
|> Map.put(
|
||||
"tag",
|
||||
tags ++
|
||||
[
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => Pleroma.Constants.activity_json_canonical_mime_type(),
|
||||
"href" => quote_url
|
||||
}
|
||||
]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
@ -112,16 +112,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
|
||||
def fix_quote_url(data), do: data
|
||||
|
||||
# https://codeberg.org/fediverse/fep/src/branch/main/fep/e232/fep-e232.md
|
||||
defp is_object_link_tag(
|
||||
%{
|
||||
def is_object_link_tag(%{
|
||||
"type" => "Link",
|
||||
"mediaType" => media_type,
|
||||
"href" => href
|
||||
} = tag
|
||||
)
|
||||
})
|
||||
when media_type in Pleroma.Constants.activity_json_mime_types() and is_binary(href) do
|
||||
true
|
||||
end
|
||||
|
||||
defp is_object_link_tag(_), do: false
|
||||
def is_object_link_tag(_), do: false
|
||||
end
|
||||
|
@ -0,0 +1,73 @@
|
||||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.QuoteToLinkTagPolicyTest do
|
||||
alias Pleroma.Web.ActivityPub.MRF.QuoteToLinkTagPolicy
|
||||
|
||||
use Pleroma.DataCase
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
test "Add quote url to Link tag" do
|
||||
quote_url = "https://gleasonator.com/objects/1234"
|
||||
|
||||
activity = %{
|
||||
"type" => "Create",
|
||||
"actor" => "https://gleasonator.com/users/alex",
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "Nice post",
|
||||
"quoteUrl" => quote_url
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, %{"object" => object}} = QuoteToLinkTagPolicy.filter(activity)
|
||||
|
||||
assert object["tag"] == [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"href" => quote_url,
|
||||
"mediaType" => Pleroma.Constants.activity_json_canonical_mime_type()
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
test "Add quote url to Link tag, append to the end" do
|
||||
quote_url = "https://gleasonator.com/objects/1234"
|
||||
|
||||
activity = %{
|
||||
"type" => "Create",
|
||||
"actor" => "https://gleasonator.com/users/alex",
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "Nice post",
|
||||
"quoteUrl" => quote_url,
|
||||
"tag" => [%{"type" => "Hashtag", "name" => "#foo"}]
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, %{"object" => object}} = QuoteToLinkTagPolicy.filter(activity)
|
||||
|
||||
assert [_, tag] = object["tag"]
|
||||
|
||||
assert tag == %{
|
||||
"type" => "Link",
|
||||
"href" => quote_url,
|
||||
"mediaType" => Pleroma.Constants.activity_json_canonical_mime_type()
|
||||
}
|
||||
end
|
||||
|
||||
test "Bypass posts without quoteUrl" do
|
||||
activity = %{
|
||||
"type" => "Create",
|
||||
"actor" => "https://gleasonator.com/users/alex",
|
||||
"object" => %{
|
||||
"type" => "Note",
|
||||
"content" => "Nice post"
|
||||
}
|
||||
}
|
||||
|
||||
assert {:ok, ^activity} = QuoteToLinkTagPolicy.filter(activity)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user