Make password reset pages translatable
[akkoma] / lib / pleroma / web / activity_pub / utils.ex
index 9c68d800f4a4ff5f99fdd286108a45ccacb737fb..6a8360def7003269319f2938fb3b2479962458c9 100644 (file)
@@ -347,13 +347,20 @@ defmodule Pleroma.Web.ActivityPub.Utils do
         %Activity{data: %{"content" => emoji, "actor" => actor}} = activity,
         object
       ) do
-    IO.inspect(emoji)
     reactions = get_cached_emoji_reactions(object)
     emoji = stripped_emoji_name(emoji)
+    url = emoji_url(emoji, activity)
+
     new_reactions =
-      case Enum.find_index(reactions, fn [candidate, _, _] -> emoji == candidate end) do
+      case Enum.find_index(reactions, fn [candidate, _, candidate_url] ->
+             if is_nil(candidate_url) do
+               emoji == candidate
+             else
+               url == candidate_url
+             end
+           end) do
         nil ->
-          reactions ++ [[emoji, [actor], emoji_url(emoji, activity)]]
+          reactions ++ [[emoji, [actor], url]]
 
         index ->
           List.update_at(
@@ -374,12 +381,18 @@ defmodule Pleroma.Web.ActivityPub.Utils do
     |> String.replace_trailing(":", "")
   end
 
-  defp emoji_url(name,
-    %Activity{
-        data: %{"tag" => [
-            %{"type" => "Emoji", "name" => name, "icon" => %{"url" => url}}
-        ]}
-    }), do: url
+  defp emoji_url(
+         name,
+         %Activity{
+           data: %{
+             "tag" => [
+               %{"type" => "Emoji", "name" => name, "icon" => %{"url" => url}}
+             ]
+           }
+         }
+       ),
+       do: url
+
   defp emoji_url(_, _), do: nil
 
   def emoji_count(reactions_list) do
@@ -387,12 +400,21 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   end
 
   def remove_emoji_reaction_from_object(
-        %Activity{data: %{"content" => emoji, "actor" => actor}},
+        %Activity{data: %{"content" => emoji, "actor" => actor}} = activity,
         object
       ) do
+    emoji = stripped_emoji_name(emoji)
     reactions = get_cached_emoji_reactions(object)
+    url = emoji_url(emoji, activity)
+
     new_reactions =
-      case Enum.find_index(reactions, fn [candidate, _, _] -> emoji == candidate end) do
+      case Enum.find_index(reactions, fn [candidate, _, candidate_url] ->
+             if is_nil(candidate_url) do
+               emoji == candidate
+             else
+               url == candidate_url
+             end
+           end) do
         nil ->
           reactions
 
@@ -523,6 +545,8 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   def get_latest_reaction(internal_activity_id, %{ap_id: ap_id}, emoji) do
     %{data: %{"object" => object_ap_id}} = Activity.get_by_id(internal_activity_id)
 
+    emoji = Pleroma.Emoji.maybe_quote(emoji)
+
     "EmojiReact"
     |> Activity.Queries.by_type()
     |> where(actor: ^ap_id)