Rearrange custom emoji processing

This commit is contained in:
FloatingGhost 2022-08-25 16:45:31 +01:00
parent 618cf7ff7f
commit 439b192829

View file

@ -55,14 +55,16 @@ def follow(follower, followed) do
{:ok, data, []}
end
@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 =
if Emoji.is_unicode_emoji?(emoji) do
defp unicode_emoji_react(object, data, emoji) do
data
|> Map.put("content", emoji)
|> Map.put("type", "EmojiReact")
end
defp custom_emoji_react(object, data, emoji) do
if String.contains?("@") do
# Attempt to resolve remote emoji
[emoji_code, instance] = String.split(emoji, "@")
else
with %{} = emojo <- Emoji.get(emoji) do
path = emojo |> Map.get(:file)
@ -87,6 +89,17 @@ def emoji_react(actor, object, emoji) do
_ -> {:error, "Emoji does not exist"}
end
end
end
@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 =
if Emoji.is_unicode_emoji?(emoji) do
unicode_emoji_react(object, data, emoji)
else
custom_emoji_react(object, data, emoji)
end
{:ok, data, meta}
end