ensure emoji reactions are fully-qualified
This commit is contained in:
parent
e40d45a585
commit
8de9033e18
|
@ -329,7 +329,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
object
|
||||
) do
|
||||
reactions = get_cached_emoji_reactions(object)
|
||||
emoji = stripped_emoji_name(emoji)
|
||||
emoji = Pleroma.Emoji.stripped_name(emoji)
|
||||
url = emoji_url(emoji, activity)
|
||||
|
||||
new_reactions =
|
||||
|
@ -356,12 +356,6 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
update_element_in_object("reaction", new_reactions, object, count)
|
||||
end
|
||||
|
||||
defp stripped_emoji_name(name) do
|
||||
name
|
||||
|> String.replace_leading(":", "")
|
||||
|> String.replace_trailing(":", "")
|
||||
end
|
||||
|
||||
defp emoji_url(
|
||||
name,
|
||||
%Activity{
|
||||
|
@ -384,7 +378,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
|||
%Activity{data: %{"content" => emoji, "actor" => actor}} = activity,
|
||||
object
|
||||
) do
|
||||
emoji = stripped_emoji_name(emoji)
|
||||
emoji = Pleroma.Emoji.stripped_name(emoji)
|
||||
reactions = get_cached_emoji_reactions(object)
|
||||
url = emoji_url(emoji, activity)
|
||||
|
||||
|
|
|
@ -209,8 +209,7 @@ defmodule Pleroma.Web.CommonAPI do
|
|||
{:ok, activity, _} <- Pipeline.common_pipeline(emoji_react, local: true) do
|
||||
{:ok, activity}
|
||||
else
|
||||
e ->
|
||||
IO.inspect(e)
|
||||
_ ->
|
||||
{:error, dgettext("errors", "Could not add reaction emoji")}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -74,7 +74,10 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionController do
|
|||
defp filter(reactions, _), do: reactions
|
||||
|
||||
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
|
||||
activity = Activity.get_by_id(activity_id)
|
||||
|
@ -86,6 +89,11 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionController do
|
|||
end
|
||||
|
||||
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
|
||||
activity = Activity.get_by_id(activity_id)
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionView do
|
|||
def emoji_name(emoji, url) do
|
||||
url = URI.parse(url)
|
||||
|
||||
if url.host == Endpoint.host() do
|
||||
if url.host == Pleroma.Web.Endpoint.host() do
|
||||
emoji
|
||||
else
|
||||
"#{emoji}@#{url.host}"
|
||||
|
|
|
@ -17,22 +17,23 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
|
|||
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 =
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|> 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)
|
||||
|
||||
# We return the status, but this our implementation detail.
|
||||
assert %{"id" => id} = result
|
||||
assert to_string(activity.id) == id
|
||||
|
||||
IO.inspect(result)
|
||||
assert result["pleroma"]["emoji_reactions"] == [
|
||||
%{
|
||||
"name" => "☕",
|
||||
"name" => "\u26A0\uFE0F",
|
||||
"count" => 1,
|
||||
"me" => true,
|
||||
"url" => nil,
|
||||
|
|
Loading…
Reference in New Issue