Unify logic for normalizing quoteUri
This commit is contained in:
parent
f9697e68c2
commit
b0a7e795e7
@ -76,27 +76,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
|
|||||||
|
|
||||||
def fix_attachments(data), do: data
|
def fix_attachments(data), do: data
|
||||||
|
|
||||||
defp fix_quote_url(%{"quoteUrl" => _quote_url} = data), do: data
|
|
||||||
|
|
||||||
# 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
|
|
||||||
defp fix_quote_url(%{"quoteURL" => quote_url} = data) do
|
|
||||||
Map.put(data, "quoteUrl", quote_url)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Misskey fallback
|
|
||||||
defp fix_quote_url(%{"_misskey_quote" => quote_url} = data) do
|
|
||||||
Map.put(data, "quoteUrl", quote_url)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp fix_quote_url(data), do: data
|
|
||||||
|
|
||||||
defp fix(data) do
|
defp fix(data) do
|
||||||
data
|
data
|
||||||
|> CommonFixes.fix_actor()
|
|> CommonFixes.fix_actor()
|
||||||
@ -105,7 +84,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
|
|||||||
|> fix_tag()
|
|> fix_tag()
|
||||||
|> fix_replies()
|
|> fix_replies()
|
||||||
|> fix_attachments()
|
|> fix_attachments()
|
||||||
|> fix_quote_url()
|
|> CommonFixes.fix_quote_url()
|
||||||
|> Transmogrifier.fix_emoji()
|
|> Transmogrifier.fix_emoji()
|
||||||
|> Transmogrifier.fix_content_map()
|
|> Transmogrifier.fix_content_map()
|
||||||
end
|
end
|
||||||
|
@ -76,4 +76,25 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes do
|
|||||||
|
|
||||||
Map.put(data, "to", to)
|
Map.put(data, "to", to)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fix_quote_url(%{"quoteUrl" => _quote_url} = data), do: data
|
||||||
|
|
||||||
|
# Fedibird
|
||||||
|
# https://github.com/fedibird/mastodon/commit/dbd7ae6cf58a92ec67c512296b4daaea0d01e6ac
|
||||||
|
def 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
|
||||||
|
def fix_quote_url(%{"quoteURL" => quote_url} = data) do
|
||||||
|
Map.put(data, "quoteUrl", quote_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Misskey fallback
|
||||||
|
def fix_quote_url(%{"_misskey_quote" => quote_url} = data) do
|
||||||
|
Map.put(data, "quoteUrl", quote_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_quote_url(data), do: data
|
||||||
end
|
end
|
||||||
|
@ -166,45 +166,27 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
|
|
||||||
def fix_in_reply_to(object, _options), do: object
|
def fix_in_reply_to(object, _options), do: object
|
||||||
|
|
||||||
def fix_quote_url(object, options \\ [])
|
def fix_quote_url_and_maybe_fetch(object, options \\ []) do
|
||||||
|
quote_url =
|
||||||
|
case Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes.fix_quote_url(object) do
|
||||||
|
%{"quoteUrl" => quote_url} -> quote_url
|
||||||
|
_ -> nil
|
||||||
|
end
|
||||||
|
|
||||||
def fix_quote_url(%{"quoteUrl" => quote_url} = object, options)
|
with {:quoting?, true} <- {:quoting?, not is_nil(quote_url)},
|
||||||
when not is_nil(quote_url) do
|
{:ok, quoted_object} <- get_obj_helper(quote_url, options),
|
||||||
with {:ok, quoted_object} <- get_obj_helper(quote_url, options),
|
|
||||||
%Activity{} <- Activity.get_create_by_object_ap_id(quoted_object.data["id"]) do
|
%Activity{} <- Activity.get_create_by_object_ap_id(quoted_object.data["id"]) do
|
||||||
Map.put(object, "quoteUrl", quoted_object.data["id"])
|
Map.put(object, "quoteUrl", quoted_object.data["id"])
|
||||||
else
|
else
|
||||||
|
{:quoting?, _} ->
|
||||||
|
object
|
||||||
|
|
||||||
e ->
|
e ->
|
||||||
Logger.warn("Couldn't fetch #{inspect(quote_url)}, error: #{inspect(e)}")
|
Logger.warn("Couldn't fetch #{inspect(quote_url)}, error: #{inspect(e)}")
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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
|
|
||||||
def fix_quote_url(%{"quoteURL" => quote_url} = object, options) do
|
|
||||||
object
|
|
||||||
|> Map.put("quoteUrl", quote_url)
|
|
||||||
|> fix_quote_url(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Misskey fallback
|
|
||||||
def fix_quote_url(%{"_misskey_quote" => quote_url} = object, options) do
|
|
||||||
object
|
|
||||||
|> Map.put("quoteUrl", quote_url)
|
|
||||||
|> fix_quote_url(options)
|
|
||||||
end
|
|
||||||
|
|
||||||
def fix_quote_url(object, _options), do: object
|
|
||||||
|
|
||||||
defp prepare_in_reply_to(in_reply_to) do
|
defp prepare_in_reply_to(in_reply_to) do
|
||||||
cond do
|
cond do
|
||||||
is_bitstring(in_reply_to) ->
|
is_bitstring(in_reply_to) ->
|
||||||
@ -493,7 +475,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||||||
|> strip_internal_fields()
|
|> strip_internal_fields()
|
||||||
|> fix_type(fetch_options)
|
|> fix_type(fetch_options)
|
||||||
|> fix_in_reply_to(fetch_options)
|
|> fix_in_reply_to(fetch_options)
|
||||||
|> fix_quote_url(fetch_options)
|
|> fix_quote_url_and_maybe_fetch(fetch_options)
|
||||||
|
|
||||||
data = Map.put(data, "object", object)
|
data = Map.put(data, "object", object)
|
||||||
options = Keyword.put(options, :local, false)
|
options = Keyword.put(options, :local, false)
|
||||||
|
@ -60,7 +60,12 @@ defmodule Pleroma.HTML.Scrubber.Default do
|
|||||||
Meta.allow_tag_with_these_attributes(:u, ["lang"])
|
Meta.allow_tag_with_these_attributes(:u, ["lang"])
|
||||||
Meta.allow_tag_with_these_attributes(:ul, ["lang"])
|
Meta.allow_tag_with_these_attributes(:ul, ["lang"])
|
||||||
|
|
||||||
Meta.allow_tag_with_this_attribute_values(:span, "class", ["h-card", "recipients-inline", "quote-inline"])
|
Meta.allow_tag_with_this_attribute_values(:span, "class", [
|
||||||
|
"h-card",
|
||||||
|
"recipients-inline",
|
||||||
|
"quote-inline"
|
||||||
|
])
|
||||||
|
|
||||||
Meta.allow_tag_with_these_attributes(:span, ["lang"])
|
Meta.allow_tag_with_these_attributes(:span, ["lang"])
|
||||||
|
|
||||||
Meta.allow_tag_with_this_attribute_values(:code, "class", ["inline"])
|
Meta.allow_tag_with_this_attribute_values(:code, "class", ["inline"])
|
||||||
|
Loading…
Reference in New Issue
Block a user