Allow reacting with remote emoji when they exist on the post #200

Merged
floatingghost merged 6 commits from remote-emoji-reactions into develop 2022-09-04 23:31:42 +00:00
5 changed files with 18 additions and 16 deletions
Showing only changes of commit 8de9033e18 - Show all commits

View file

@ -329,7 +329,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
object object
) do ) do
reactions = get_cached_emoji_reactions(object) reactions = get_cached_emoji_reactions(object)
emoji = stripped_emoji_name(emoji) emoji = Pleroma.Emoji.stripped_name(emoji)
url = emoji_url(emoji, activity) url = emoji_url(emoji, activity)
new_reactions = new_reactions =
@ -356,12 +356,6 @@ defmodule Pleroma.Web.ActivityPub.Utils do
update_element_in_object("reaction", new_reactions, object, count) update_element_in_object("reaction", new_reactions, object, count)
end end
defp stripped_emoji_name(name) do
name
|> String.replace_leading(":", "")
|> String.replace_trailing(":", "")
end
defp emoji_url( defp emoji_url(
name, name,
%Activity{ %Activity{
@ -384,7 +378,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
%Activity{data: %{"content" => emoji, "actor" => actor}} = activity, %Activity{data: %{"content" => emoji, "actor" => actor}} = activity,
object object
) do ) do
emoji = stripped_emoji_name(emoji) emoji = Pleroma.Emoji.stripped_name(emoji)
reactions = get_cached_emoji_reactions(object) reactions = get_cached_emoji_reactions(object)
url = emoji_url(emoji, activity) url = emoji_url(emoji, activity)

View file

@ -209,8 +209,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
e -> _ ->
IO.inspect(e)
{:error, dgettext("errors", "Could not add reaction emoji")} {:error, dgettext("errors", "Could not add reaction emoji")}
end end
end end

View file

@ -74,7 +74,10 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionController do
defp filter(reactions, _), do: reactions defp filter(reactions, _), do: reactions
def create(%{assigns: %{user: user}} = conn, %{id: activity_id, emoji: emoji}) do def create(%{assigns: %{user: user}} = conn, %{id: activity_id, emoji: emoji}) do
emoji = Pleroma.Emoji.maybe_quote(emoji) emoji =
emoji
|> Pleroma.Emoji.fully_qualify_emoji()
|> Pleroma.Emoji.maybe_quote()
with {:ok, _activity} <- CommonAPI.react_with_emoji(activity_id, user, emoji) do with {:ok, _activity} <- CommonAPI.react_with_emoji(activity_id, user, emoji) do
activity = Activity.get_by_id(activity_id) activity = Activity.get_by_id(activity_id)
@ -86,6 +89,11 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionController do
end end
def delete(%{assigns: %{user: user}} = conn, %{id: activity_id, emoji: emoji}) do def delete(%{assigns: %{user: user}} = conn, %{id: activity_id, emoji: emoji}) do
emoji =
emoji
|> Pleroma.Emoji.fully_qualify_emoji()
|> Pleroma.Emoji.maybe_quote()
with {:ok, _activity} <- CommonAPI.unreact_with_emoji(activity_id, user, emoji) do with {:ok, _activity} <- CommonAPI.unreact_with_emoji(activity_id, user, emoji) do
activity = Activity.get_by_id(activity_id) activity = Activity.get_by_id(activity_id)

View file

@ -13,7 +13,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionView do
def emoji_name(emoji, url) do def emoji_name(emoji, url) do
url = URI.parse(url) url = URI.parse(url)
if url.host == Endpoint.host() do if url.host == Pleroma.Web.Endpoint.host() do
emoji emoji
else else
"#{emoji}@#{url.host}" "#{emoji}@#{url.host}"

View file

@ -17,22 +17,23 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
user = insert(:user) user = insert(:user)
other_user = insert(:user) other_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{status: "#cofe"}) note = insert(:note, user: user, reactions: %{reactions: %{"👍" => [other_user.ap_id]}})
activity = insert(:note_activity, note: note, user: user)
result = result =
conn conn
|> assign(:user, other_user) |> assign(:user, other_user)
|> assign(:token, insert(:oauth_token, user: other_user, scopes: ["write:statuses"])) |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["write:statuses"]))
|> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/") |> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/\u26A0")
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
# We return the status, but this our implementation detail. # We return the status, but this our implementation detail.
assert %{"id" => id} = result assert %{"id" => id} = result
assert to_string(activity.id) == id assert to_string(activity.id) == id
IO.inspect(result)
assert result["pleroma"]["emoji_reactions"] == [ assert result["pleroma"]["emoji_reactions"] == [
%{ %{
"name" => "", "name" => "\u26A0\uFE0F",
"count" => 1, "count" => 1,
"me" => true, "me" => true,
"url" => nil, "url" => nil,