Remove _misskey_reaction matching
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful

This commit is contained in:
FloatingGhost 2023-03-10 18:14:40 +00:00
parent 08dfce98be
commit c5838ebb43
4 changed files with 14 additions and 25 deletions

View file

@ -21,6 +21,7 @@ defmodule Pleroma.Emoji do
:named_table, :named_table,
{:read_concurrency, true} {:read_concurrency, true}
] ]
@emoji_regex ~r/:[A-Za-z0-9_-]+(@.+)?:/
defstruct [:code, :file, :tags, :safe_code, :safe_file] defstruct [:code, :file, :tags, :safe_code, :safe_file]
@ -205,4 +206,7 @@ def fully_qualify_emoji(unquote(unqualified)), do: unquote(qualified)
end end
def fully_qualify_emoji(emoji), do: emoji def fully_qualify_emoji(emoji), do: emoji
def matches_shortcode?(nil), do: false
def matches_shortcode?(s), do: Regex.match?(@emoji_regex, s)
end end

View file

@ -13,7 +13,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
@primary_key false @primary_key false
@emoji_regex ~r/:[A-Za-z0-9_-]+(@.+)?:/
embedded_schema do embedded_schema do
quote do quote do
@ -75,9 +74,6 @@ defp fix(data) do
end end
end end
defp matches_shortcode?(nil), do: false
defp matches_shortcode?(s), do: Regex.match?(@emoji_regex, s)
defp fix_emoji_qualification(%{"content" => emoji} = data) do defp fix_emoji_qualification(%{"content" => emoji} = data) do
new_emoji = Pleroma.Emoji.fully_qualify_emoji(emoji) new_emoji = Pleroma.Emoji.fully_qualify_emoji(emoji)
@ -98,7 +94,7 @@ defp fix_emoji_qualification(data), do: data
defp validate_emoji(cng) do defp validate_emoji(cng) do
content = get_field(cng, :content) content = get_field(cng, :content)
if Emoji.is_unicode_emoji?(content) || matches_shortcode?(content) do if Emoji.is_unicode_emoji?(content) || Emoji.matches_shortcode?(content) do
cng cng
else else
cng cng

View file

@ -419,28 +419,17 @@ def handle_incoming(%{"id" => id}, _options) when is_binary(id) and byte_size(id
def handle_incoming( def handle_incoming(
%{ %{
"type" => "Like", "type" => "Like",
"_misskey_reaction" => reaction, "content" => reaction
"tag" => _
} = data, } = data,
options options
) do ) do
data if Pleroma.Emoji.is_unicode_emoji?(reaction) or Pleroma.Emoji.matches_shortcode?(reaction) do
|> Map.put("type", "EmojiReact") data
|> Map.put("content", reaction) |> Map.put("type", "EmojiReact")
|> handle_incoming(options) |> handle_incoming(options)
end else
handle_incoming(options)
def handle_incoming( end
%{
"type" => "Like",
"_misskey_reaction" => reaction
} = data,
options
) do
data
|> Map.put("type", "EmojiReact")
|> Map.put("content", reaction)
|> handle_incoming(options)
end end
def handle_incoming( def handle_incoming(

View file

@ -63,7 +63,7 @@ test "it works for incoming misskey likes that contain unicode emojis, turning t
File.read!("test/fixtures/misskey-like.json") File.read!("test/fixtures/misskey-like.json")
|> Jason.decode!() |> Jason.decode!()
|> Map.put("object", activity.data["object"]) |> Map.put("object", activity.data["object"])
|> Map.put("_misskey_reaction", "") |> Map.put("content", "")
_actor = insert(:user, ap_id: data["actor"], local: false) _actor = insert(:user, ap_id: data["actor"], local: false)