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 @@ def reload 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 @@ def follow(follower, followed) 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 @@ defp fix(data) 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 @@ def handle_incoming(
} = data,
options
) do
IO.inspect(data)
data
|> Map.put("type", "EmojiReact")
|> Map.put("content", reaction)

View file

@ -261,8 +261,7 @@ def react_with_emoji(id, user, emoji) 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