add outbound reacts
authorFloatingGhost <hannah@coffee-and-dreams.uk>
Wed, 8 Jun 2022 11:36:38 +0000 (12:36 +0100)
committerFloatingGhost <hannah@coffee-and-dreams.uk>
Wed, 8 Jun 2022 11:36:38 +0000 (12:36 +0100)
lib/pleroma/emoji.ex
lib/pleroma/web/activity_pub/builder.ex
lib/pleroma/web/activity_pub/object_validators/emoji_react_validator.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/common_api.ex

index 12485011407ef257cd07b1ea89ed22edf2138b12..f484f96a0e9ea8f4154af735038b0fe7de270a50 100644 (file)
@@ -50,6 +50,14 @@ defmodule Pleroma.Emoji do
   @doc "Returns the path of the emoji `name`."
   @spec get(String.t()) :: String.t() | nil
   def get(name) do
+    name = if String.starts_with?(name, ":") do
+      name
+      |> String.replace_leading(":", "")
+      |> String.replace_trailing(":", "")
+    else
+      name
+    end
+
     case :ets.lookup(@ets, name) do
       [{_, path}] -> path
       _ -> nil
index 647ccf432d9ef60fe953e05332c42025000137c5..0ba17a4d5b1f9dd6b36fbd044c21fd3823f42193 100644 (file)
@@ -16,6 +16,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do
   alias Pleroma.Web.ActivityPub.Utils
   alias Pleroma.Web.ActivityPub.Visibility
   alias Pleroma.Web.CommonAPI.ActivityDraft
+  alias Pleroma.Web.Endpoint
 
   require Pleroma.Constants
 
@@ -57,10 +58,29 @@ defmodule Pleroma.Web.ActivityPub.Builder do
   @spec emoji_react(User.t(), Object.t(), String.t()) :: {:ok, map(), keyword()}
   def emoji_react(actor, object, emoji) do
     with {:ok, data, meta} <- object_action(actor, object) do
-      data =
+      data = if Emoji.is_unicode_emoji?(emoji) do
+        data
+        |> Map.put("content", emoji)
+        |> Map.put("type", "EmojiReact")
+      else
+        emojo = Emoji.get(emoji)
+        path = emojo |> Map.get(:file)
+        url = "#{Endpoint.url()}#{path}"
         data
         |> Map.put("content", emoji)
         |> Map.put("type", "EmojiReact")
+        |> Map.put("tag", [
+            %{}
+            |> Map.put("id", url)
+            |> Map.put("type", "Emoji")
+            |> Map.put("name", emojo.code)
+            |> Map.put("icon",
+                %{}
+                |> Map.put("type", "Image")
+                |> Map.put("url", url)
+            )
+        ])
+      end
 
       {:ok, data, meta}
     end
index 45c28beedbe040a8dbf68c0d8f53ae60c95c39d3..f0eb5417c4991520071a4024bd37419fa4e5b82d 100644 (file)
@@ -72,7 +72,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
 
   defp validate_emoji(cng) do
     content = get_field(cng, :content)
-    IO.inspect(Pleroma.Emoji.is_unicode_emoji?(content))
     if Pleroma.Emoji.is_unicode_emoji?(content) || Regex.match?(@emoji_regex, content) do
       cng
     else
index 25aaba1a6a947cb6aa4a9e4cbd39b1fcccc24d46..f5a7866b675884e4ef8a22a4040878ada6a3710e 100644 (file)
@@ -424,6 +424,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
         } = data,
         options
       ) do
+    IO.inspect(data)
     data
     |> Map.put("type", "EmojiReact")
     |> Map.put("content", reaction)
index 3266b1c607017676a00dcb8dd2d45969b8e74a46..92afd5cb61e6533ebfc0359742b8eee21bc1ed14 100644 (file)
@@ -261,8 +261,7 @@ defmodule Pleroma.Web.CommonAPI do
          {:ok, activity, _} <- Pipeline.common_pipeline(emoji_react, local: true) do
       {:ok, activity}
     else
-      _ ->
-        {:error, dgettext("errors", "Could not add reaction emoji")}
+      _ -> {:error, dgettext("errors", "Could not add reaction emoji")}
     end
   end