add outbound reacts

This commit is contained in:
FloatingGhost 2022-06-08 12:36:38 +01:00
parent ad0b8c095c
commit c5467d04e4
5 changed files with 31 additions and 4 deletions

View 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

View 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

View 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

View 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)

View 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