add outbound reacts
This commit is contained in:
parent
ad0b8c095c
commit
c5467d04e4
5 changed files with 31 additions and 4 deletions
|
@ -50,6 +50,14 @@ defmodule Pleroma.Emoji do
|
||||||
@doc "Returns the path of the emoji `name`."
|
@doc "Returns the path of the emoji `name`."
|
||||||
@spec get(String.t()) :: String.t() | nil
|
@spec get(String.t()) :: String.t() | nil
|
||||||
def get(name) do
|
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
|
case :ets.lookup(@ets, name) do
|
||||||
[{_, path}] -> path
|
[{_, path}] -> path
|
||||||
_ -> nil
|
_ -> nil
|
||||||
|
|
|
@ -16,6 +16,7 @@ defmodule Pleroma.Web.ActivityPub.Builder do
|
||||||
alias Pleroma.Web.ActivityPub.Utils
|
alias Pleroma.Web.ActivityPub.Utils
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
alias Pleroma.Web.CommonAPI.ActivityDraft
|
alias Pleroma.Web.CommonAPI.ActivityDraft
|
||||||
|
alias Pleroma.Web.Endpoint
|
||||||
|
|
||||||
require Pleroma.Constants
|
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()}
|
@spec emoji_react(User.t(), Object.t(), String.t()) :: {:ok, map(), keyword()}
|
||||||
def emoji_react(actor, object, emoji) do
|
def emoji_react(actor, object, emoji) do
|
||||||
with {:ok, data, meta} <- object_action(actor, object) do
|
with {:ok, data, meta} <- object_action(actor, object) do
|
||||||
data =
|
data = if Emoji.is_unicode_emoji?(emoji) do
|
||||||
data
|
data
|
||||||
|> Map.put("content", emoji)
|
|> Map.put("content", emoji)
|
||||||
|> Map.put("type", "EmojiReact")
|
|> 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}
|
{:ok, data, meta}
|
||||||
end
|
end
|
||||||
|
|
|
@ -72,7 +72,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
|
||||||
|
|
||||||
defp validate_emoji(cng) do
|
defp validate_emoji(cng) do
|
||||||
content = get_field(cng, :content)
|
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
|
if Pleroma.Emoji.is_unicode_emoji?(content) || Regex.match?(@emoji_regex, content) do
|
||||||
cng
|
cng
|
||||||
else
|
else
|
||||||
|
|
|
@ -424,6 +424,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
} = data,
|
} = data,
|
||||||
options
|
options
|
||||||
) do
|
) do
|
||||||
|
IO.inspect(data)
|
||||||
data
|
data
|
||||||
|> Map.put("type", "EmojiReact")
|
|> Map.put("type", "EmojiReact")
|
||||||
|> Map.put("content", reaction)
|
|> Map.put("content", reaction)
|
||||||
|
|
|
@ -261,8 +261,7 @@ defmodule Pleroma.Web.CommonAPI do
|
||||||
{:ok, activity, _} <- Pipeline.common_pipeline(emoji_react, local: true) do
|
{:ok, activity, _} <- Pipeline.common_pipeline(emoji_react, local: true) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
_ ->
|
_ -> {:error, dgettext("errors", "Could not add reaction emoji")}
|
||||||
{:error, dgettext("errors", "Could not add reaction emoji")}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue