Parse object link as quoteUrl
This commit is contained in:
parent
163e563733
commit
e9cd004ba1
|
@ -83,4 +83,11 @@ defmodule Pleroma.Constants do
|
|||
)
|
||||
|
||||
const(upload_object_types, do: ["Document", "Image"])
|
||||
|
||||
const(activity_json_mime_types,
|
||||
do: [
|
||||
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
|
||||
"application/activity+json"
|
||||
]
|
||||
)
|
||||
end
|
||||
|
|
|
@ -99,6 +99,7 @@ defp fix(data) do
|
|||
data
|
||||
|> CommonFixes.fix_actor()
|
||||
|> CommonFixes.fix_object_defaults()
|
||||
|> CommonFixes.fix_quote_url()
|
||||
|> Transmogrifier.fix_emoji()
|
||||
|> fix_url()
|
||||
|> fix_content()
|
||||
|
|
|
@ -10,6 +10,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
|
|||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
def cast_and_filter_recipients(message, field, follower_collection, field_fallback \\ []) do
|
||||
{:ok, data} = ObjectValidators.Recipients.cast(message[field] || field_fallback)
|
||||
|
||||
|
@ -96,5 +98,30 @@ def fix_quote_url(%{"_misskey_quote" => quote_url} = data) do
|
|||
Map.put(data, "quoteUrl", quote_url)
|
||||
end
|
||||
|
||||
def fix_quote_url(data), do: data
|
||||
def fix_quote_url(%{"tag" => [_ | _] = tags} = data) do
|
||||
tag = Enum.find(tags, &is_object_link_tag/1)
|
||||
|
||||
if not is_nil(tag) do
|
||||
data
|
||||
|> Map.put("quoteUrl", tag["href"])
|
||||
else
|
||||
data
|
||||
end
|
||||
end
|
||||
|
||||
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(
|
||||
%{
|
||||
"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
|
||||
end
|
||||
|
|
|
@ -62,6 +62,7 @@ defp fix(data) do
|
|||
data
|
||||
|> CommonFixes.fix_actor()
|
||||
|> CommonFixes.fix_object_defaults()
|
||||
|> CommonFixes.fix_quote_url()
|
||||
|> Transmogrifier.fix_emoji()
|
||||
|> fix_closed()
|
||||
end
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
"type": "Note",
|
||||
"content": "This is a quote:<br>RE: https://server.example/objects/123",
|
||||
"tag": [
|
||||
{
|
||||
"type": "Link",
|
||||
"mediaType": "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"",
|
||||
"href": "https://server.example/objects/123",
|
||||
"name": "RE: https://server.example/objects/123"
|
||||
}
|
||||
],
|
||||
"id": "https://server.example/objects/1",
|
||||
"to": "https://server.example/users/1",
|
||||
"attributedTo": "https://server.example/users/1",
|
||||
"actor": "https://server.example/users/1"
|
||||
}
|
|
@ -146,4 +146,16 @@ test "Misskey quote post" do
|
|||
assert cng.valid?
|
||||
assert cng.changes.quoteUrl == "https://misskey.io/notes/8vs6wxufd0"
|
||||
end
|
||||
|
||||
test "Parse tag as quote" do
|
||||
# https://codeberg.org/fediverse/fep/src/branch/main/fep/e232/fep-e232.md
|
||||
|
||||
insert(:user, ap_id: "https://server.example/users/1")
|
||||
|
||||
data = File.read!("test/fixtures/quote_post/fep-e232-tag-example.json") |> Jason.decode!()
|
||||
cng = ArticleNotePageValidator.cast_and_validate(data)
|
||||
|
||||
assert cng.valid?
|
||||
assert cng.changes.quoteUrl == "https://server.example/objects/123"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue