@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
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.CommonAPI.ActivityDraft
+ alias Pleroma.Web.Endpoint
require Pleroma.Constants
@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
{: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