InlineQuotePolicy: skip objects which already have an .inline-quote span
This commit is contained in:
parent
79fca39faf
commit
f9697e68c2
|
@ -10,10 +10,21 @@ defp build_inline_quote(prefix, url) do
|
||||||
"<span class=\"quote-inline\"><br/><br/>#{prefix}: <a href=\"#{url}\">#{url}</a></span>"
|
"<span class=\"quote-inline\"><br/><br/>#{prefix}: <a href=\"#{url}\">#{url}</a></span>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp has_inline_quote?(content, quote_url) do
|
||||||
|
cond do
|
||||||
|
# Does the quote URL exist in the content?
|
||||||
|
content =~ quote_url -> true
|
||||||
|
# Does the content already have a .quote-inline span?
|
||||||
|
content =~ "<span class=\"quote-inline\">" -> true
|
||||||
|
# No inline quote found
|
||||||
|
true -> false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defp filter_object(%{"quoteUrl" => quote_url} = object) do
|
defp filter_object(%{"quoteUrl" => quote_url} = object) do
|
||||||
content = object["content"] || ""
|
content = object["content"] || ""
|
||||||
|
|
||||||
if content =~ quote_url do
|
if has_inline_quote?(content, quote_url) do
|
||||||
object
|
object
|
||||||
else
|
else
|
||||||
prefix = Pleroma.Config.get([:mrf_inline_quote, :prefix])
|
prefix = Pleroma.Config.get([:mrf_inline_quote, :prefix])
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
{
|
||||||
|
"ostatus": "http://ostatus.org#",
|
||||||
|
"atomUri": "ostatus:atomUri",
|
||||||
|
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||||
|
"conversation": "ostatus:conversation",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"votersCount": "toot:votersCount",
|
||||||
|
"fedibird": "http://fedibird.com/ns#",
|
||||||
|
"quoteUri": "fedibird:quoteUri",
|
||||||
|
"expiry": "fedibird:expiry"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"id": "https://fedibird.com/users/noellabo/statuses/107712183700212249",
|
||||||
|
"type": "Note",
|
||||||
|
"summary": null,
|
||||||
|
"inReplyTo": null,
|
||||||
|
"published": "2022-01-30T15:44:50Z",
|
||||||
|
"url": "https://fedibird.com/@noellabo/107712183700212249",
|
||||||
|
"attributedTo": "https://fedibird.com/users/noellabo",
|
||||||
|
"to": [
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
],
|
||||||
|
"cc": [
|
||||||
|
"https://fedibird.com/users/noellabo/followers"
|
||||||
|
],
|
||||||
|
"sensitive": false,
|
||||||
|
"atomUri": "https://fedibird.com/users/noellabo/statuses/107712183700212249",
|
||||||
|
"inReplyToAtomUri": null,
|
||||||
|
"conversation": "tag:fedibird.com,2022-01-30:objectId=107712183700170473:objectType=Conversation",
|
||||||
|
"context": "https://fedibird.com/contexts/107712183700170473",
|
||||||
|
"quoteUri": "https://unnerv.jp/users/UN_NERV/statuses/107712176849067434",
|
||||||
|
"_misskey_quote": "https://unnerv.jp/users/UN_NERV/statuses/107712176849067434",
|
||||||
|
"_misskey_content": "揺れていたようだ",
|
||||||
|
"content": "<p>揺れていたようだ<span class=\"quote-inline\"><br/>QT: <a class=\"status-url-link\" data-status-account-acct=\"UN_NERV@unnerv.jp\" data-status-id=\"107712177062934465\" href=\"https://unnerv.jp/@UN_NERV/107712176849067434\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">unnerv.jp/@UN_NERV/10771217684</span><span class=\"invisible\">9067434</span></a></span></p>",
|
||||||
|
"contentMap": {
|
||||||
|
"ja": "<p>揺れていたようだ<span class=\"quote-inline\"><br/>QT: <a class=\"status-url-link\" data-status-account-acct=\"UN_NERV@unnerv.jp\" data-status-id=\"107712177062934465\" href=\"https://unnerv.jp/@UN_NERV/107712176849067434\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">unnerv.jp/@UN_NERV/10771217684</span><span class=\"invisible\">9067434</span></a></span></p>"
|
||||||
|
},
|
||||||
|
"attachment": [],
|
||||||
|
"tag": [],
|
||||||
|
"replies": {
|
||||||
|
"id": "https://fedibird.com/users/noellabo/statuses/107712183700212249/replies",
|
||||||
|
"type": "Collection",
|
||||||
|
"first": {
|
||||||
|
"type": "CollectionPage",
|
||||||
|
"next": "https://fedibird.com/users/noellabo/statuses/107712183700212249/replies?only_other_accounts=true&page=true",
|
||||||
|
"partOf": "https://fedibird.com/users/noellabo/statuses/107712183700212249/replies",
|
||||||
|
"items": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,4 +72,21 @@ test "ignores Fedibird quote posts" do
|
||||||
{:ok, filtered} = InlineQuotePolicy.filter(activity)
|
{:ok, filtered} = InlineQuotePolicy.filter(activity)
|
||||||
assert filtered == activity
|
assert filtered == activity
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "skips objects which already have an .inline-quote span" do
|
||||||
|
object =
|
||||||
|
File.read!("test/fixtures/quote_post/fedibird_quote_mismatched.json") |> Jason.decode!()
|
||||||
|
|
||||||
|
# Normally the ObjectValidator will fix this before it reaches MRF
|
||||||
|
object = Map.put(object, "quoteUrl", object["quoteUri"])
|
||||||
|
|
||||||
|
activity = %{
|
||||||
|
"type" => "Create",
|
||||||
|
"actor" => "https://fedibird.com/users/noellabo",
|
||||||
|
"object" => object
|
||||||
|
}
|
||||||
|
|
||||||
|
{:ok, filtered} = InlineQuotePolicy.filter(activity)
|
||||||
|
assert filtered == activity
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue