Merge remote-tracking branch 'pleroma/quote-post' into merge-upstream
This commit is contained in:
commit
281ccab704
8 changed files with 110 additions and 12 deletions
|
@ -6,8 +6,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy do
|
||||||
@moduledoc "Force a quote line into the message content."
|
@moduledoc "Force a quote line into the message content."
|
||||||
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
@behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
|
||||||
defp build_inline_quote(prefix, url, br) do
|
defp build_inline_quote(prefix, url) do
|
||||||
"<span class=\"quote-inline\">#{String.duplicate("<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 filter_object(%{"quoteUrl" => quote_url} = object) do
|
defp filter_object(%{"quoteUrl" => quote_url} = object) do
|
||||||
|
@ -18,12 +18,13 @@ defp filter_object(%{"quoteUrl" => quote_url} = object) do
|
||||||
else
|
else
|
||||||
prefix = Pleroma.Config.get([:mrf_inline_quote, :prefix])
|
prefix = Pleroma.Config.get([:mrf_inline_quote, :prefix])
|
||||||
|
|
||||||
inline_quote =
|
content =
|
||||||
if String.ends_with?(content, "</p>"),
|
if String.ends_with?(content, "</p>"),
|
||||||
do: build_inline_quote(prefix, quote_url, 0),
|
do:
|
||||||
else: build_inline_quote(prefix, quote_url, 2)
|
String.trim_trailing(content, "</p>") <>
|
||||||
|
build_inline_quote(prefix, quote_url) <> "</p>",
|
||||||
|
else: content <> build_inline_quote(prefix, quote_url)
|
||||||
|
|
||||||
content = content <> inline_quote
|
|
||||||
Map.put(object, "content", content)
|
Map.put(object, "content", content)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -67,7 +67,13 @@ defp fix_replies(data), do: data
|
||||||
|
|
||||||
defp fix_quote_url(%{"quoteUrl" => _quote_url} = data), do: data
|
defp fix_quote_url(%{"quoteUrl" => _quote_url} = data), do: data
|
||||||
|
|
||||||
# Fix for Fedibird
|
# Fedibird
|
||||||
|
# https://github.com/fedibird/mastodon/commit/dbd7ae6cf58a92ec67c512296b4daaea0d01e6ac
|
||||||
|
defp fix_quote_url(%{"quoteUri" => quote_url} = data) do
|
||||||
|
Map.put(data, "quoteUrl", quote_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Old Fedibird (bug)
|
||||||
# https://github.com/fedibird/mastodon/issues/9
|
# https://github.com/fedibird/mastodon/issues/9
|
||||||
defp fix_quote_url(%{"quoteURL" => quote_url} = data) do
|
defp fix_quote_url(%{"quoteURL" => quote_url} = data) do
|
||||||
Map.put(data, "quoteUrl", quote_url)
|
Map.put(data, "quoteUrl", quote_url)
|
||||||
|
|
|
@ -181,7 +181,15 @@ def fix_quote_url(%{"quoteUrl" => quote_url} = object, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fix for Fedibird
|
# Fedibird
|
||||||
|
# https://github.com/fedibird/mastodon/commit/dbd7ae6cf58a92ec67c512296b4daaea0d01e6ac
|
||||||
|
def fix_quote_url(%{"quoteUri" => quote_url} = object, options) do
|
||||||
|
object
|
||||||
|
|> Map.put("quoteUrl", quote_url)
|
||||||
|
|> fix_quote_url(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Old Fedibird (bug)
|
||||||
# https://github.com/fedibird/mastodon/issues/9
|
# https://github.com/fedibird/mastodon/issues/9
|
||||||
def fix_quote_url(%{"quoteURL" => quote_url} = object, options) do
|
def fix_quote_url(%{"quoteURL" => quote_url} = object, options) do
|
||||||
object
|
object
|
||||||
|
@ -661,6 +669,17 @@ def set_reply_to_uri(%{"inReplyTo" => in_reply_to} = object) when is_binary(in_r
|
||||||
|
|
||||||
def set_reply_to_uri(obj), do: obj
|
def set_reply_to_uri(obj), do: obj
|
||||||
|
|
||||||
|
def set_quote_url(%{"quoteUrl" => quote_url} = object) when is_binary(quote_url) do
|
||||||
|
Map.merge(object, %{
|
||||||
|
# Fedibird quote
|
||||||
|
"quoteUri" => quote_url,
|
||||||
|
# Misskey quote
|
||||||
|
"_misskey_quote" => quote_url
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_quote_url(obj), do: obj
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Serialized Mastodon-compatible `replies` collection containing _self-replies_.
|
Serialized Mastodon-compatible `replies` collection containing _self-replies_.
|
||||||
Based on Mastodon's ActivityPub::NoteSerializer#replies.
|
Based on Mastodon's ActivityPub::NoteSerializer#replies.
|
||||||
|
@ -715,6 +734,7 @@ def prepare_object(object) do
|
||||||
|> prepare_attachments
|
|> prepare_attachments
|
||||||
|> set_conversation
|
|> set_conversation
|
||||||
|> set_reply_to_uri
|
|> set_reply_to_uri
|
||||||
|
|> set_quote_url
|
||||||
|> set_replies
|
|> set_replies
|
||||||
|> strip_internal_fields
|
|> strip_internal_fields
|
||||||
|> strip_internal_tags
|
|> strip_internal_tags
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
"ostatus": "http://ostatus.org#",
|
"ostatus": "http://ostatus.org#",
|
||||||
"schema": "http://schema.org#",
|
"schema": "http://schema.org#",
|
||||||
"toot": "http://joinmastodon.org/ns#",
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"misskey": "https://misskey-hub.net/ns#",
|
||||||
|
"fedibird": "http://fedibird.com/ns#",
|
||||||
"value": "schema:value",
|
"value": "schema:value",
|
||||||
"sensitive": "as:sensitive",
|
"sensitive": "as:sensitive",
|
||||||
"litepub": "http://litepub.social/ns#",
|
"litepub": "http://litepub.social/ns#",
|
||||||
|
@ -27,6 +29,8 @@
|
||||||
"@type": "@id"
|
"@type": "@id"
|
||||||
},
|
},
|
||||||
"quoteUrl": "as:quoteUrl",
|
"quoteUrl": "as:quoteUrl",
|
||||||
|
"quoteUri": "fedibird:quoteUri",
|
||||||
|
"_misskey_quote": "misskey:_misskey_quote",
|
||||||
"oauthRegistrationEndpoint": {
|
"oauthRegistrationEndpoint": {
|
||||||
"@id": "litepub:oauthRegistrationEndpoint",
|
"@id": "litepub:oauthRegistrationEndpoint",
|
||||||
"@type": "@id"
|
"@type": "@id"
|
||||||
|
|
54
test/fixtures/quote_post/fedibird_quote_uri.json
vendored
Normal file
54
test/fixtures/quote_post/fedibird_quote_uri.json
vendored
Normal file
|
@ -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/107699335988346142",
|
||||||
|
"type": "Note",
|
||||||
|
"summary": null,
|
||||||
|
"inReplyTo": null,
|
||||||
|
"published": "2022-01-28T09:17:30Z",
|
||||||
|
"url": "https://fedibird.com/@noellabo/107699335988346142",
|
||||||
|
"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/107699335988346142",
|
||||||
|
"inReplyToAtomUri": null,
|
||||||
|
"conversation": "tag:fedibird.com,2022-01-28:objectId=107699335988345290:objectType=Conversation",
|
||||||
|
"context": "https://fedibird.com/contexts/107699335988345290",
|
||||||
|
"quoteUri": "https://fedibird.com/users/yamako/statuses/107699333438289729",
|
||||||
|
"_misskey_quote": "https://fedibird.com/users/yamako/statuses/107699333438289729",
|
||||||
|
"_misskey_content": "美味しそう",
|
||||||
|
"content": "<p>美味しそう<span class=\"quote-inline\"><br/>QT: <a class=\"status-url-link\" data-status-account-acct=\"yamako\" data-status-id=\"107699333438289729\" href=\"https://fedibird.com/@yamako/107699333438289729\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">fedibird.com/@yamako/107699333</span><span class=\"invisible\">438289729</span></a></span></p>",
|
||||||
|
"contentMap": {
|
||||||
|
"ja": "<p>美味しそう<span class=\"quote-inline\"><br/>QT: <a class=\"status-url-link\" data-status-account-acct=\"yamako\" data-status-id=\"107699333438289729\" href=\"https://fedibird.com/@yamako/107699333438289729\" rel=\"nofollow noopener noreferrer\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">fedibird.com/@yamako/107699333</span><span class=\"invisible\">438289729</span></a></span></p>"
|
||||||
|
},
|
||||||
|
"attachment": [],
|
||||||
|
"tag": [],
|
||||||
|
"replies": {
|
||||||
|
"id": "https://fedibird.com/users/noellabo/statuses/107699335988346142/replies",
|
||||||
|
"type": "Collection",
|
||||||
|
"first": {
|
||||||
|
"type": "CollectionPage",
|
||||||
|
"next": "https://fedibird.com/users/noellabo/statuses/107699335988346142/replies?only_other_accounts=true&page=true",
|
||||||
|
"partOf": "https://fedibird.com/users/noellabo/statuses/107699335988346142/replies",
|
||||||
|
"items": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ test "adds quote URL to post content" do
|
||||||
{:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
|
{:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
|
||||||
|
|
||||||
assert filtered ==
|
assert filtered ==
|
||||||
"Nice post<span class=\"quote-inline\"><br><br>RT: <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span>"
|
"Nice post<span class=\"quote-inline\"><br/><br/>RT: <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span>"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "doesn't add line breaks to markdown posts" do
|
test "doesn't add line breaks to markdown posts" do
|
||||||
|
@ -41,7 +41,7 @@ test "doesn't add line breaks to markdown posts" do
|
||||||
{:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
|
{:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
|
||||||
|
|
||||||
assert filtered ==
|
assert filtered ==
|
||||||
"<p>Nice post</p><span class=\"quote-inline\">RT: <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span>"
|
"<p>Nice post<span class=\"quote-inline\"><br/><br/>RT: <a href=\"https://gleasonator.com/objects/1234\">https://gleasonator.com/objects/1234</a></span></p>"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "ignores Misskey quote posts" do
|
test "ignores Misskey quote posts" do
|
||||||
|
|
|
@ -43,6 +43,16 @@ test "Fedibird quote post" do
|
||||||
assert cng.changes.quoteUrl == "https://misskey.io/notes/8vsn2izjwh"
|
assert cng.changes.quoteUrl == "https://misskey.io/notes/8vsn2izjwh"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "Fedibird quote post with quoteUri field" do
|
||||||
|
insert(:user, ap_id: "https://fedibird.com/users/noellabo")
|
||||||
|
|
||||||
|
data = File.read!("test/fixtures/quote_post/fedibird_quote_uri.json") |> Jason.decode!()
|
||||||
|
cng = ArticleNotePageValidator.cast_and_validate(data)
|
||||||
|
|
||||||
|
assert cng.valid?
|
||||||
|
assert cng.changes.quoteUrl == "https://fedibird.com/users/yamako/statuses/107699333438289729"
|
||||||
|
end
|
||||||
|
|
||||||
test "Misskey quote post" do
|
test "Misskey quote post" do
|
||||||
insert(:user, ap_id: "https://misskey.io/users/7rkrarq81i")
|
insert(:user, ap_id: "https://misskey.io/users/7rkrarq81i")
|
||||||
|
|
||||||
|
|
|
@ -332,8 +332,11 @@ test "it prepares a quote post" do
|
||||||
|
|
||||||
{:ok, modified} = Transmogrifier.prepare_outgoing(quote_post.data)
|
{:ok, modified} = Transmogrifier.prepare_outgoing(quote_post.data)
|
||||||
|
|
||||||
quoted_post = Object.normalize(quoted_post)
|
%{data: %{"id" => quote_id}} = Object.normalize(quoted_post)
|
||||||
assert modified["object"]["quoteUrl"] == quoted_post.data["id"]
|
|
||||||
|
assert modified["object"]["quoteUrl"] == quote_id
|
||||||
|
assert modified["object"]["quoteUri"] == quote_id
|
||||||
|
assert modified["object"]["_misskey_quote"] == quote_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue