Transmogrifier: Handle incoming Undos for EmojiReactions.
This commit is contained in:
parent
0e41951eab
commit
c9043c6c80
|
@ -721,6 +721,28 @@ def handle_incoming(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_incoming(
|
||||||
|
%{
|
||||||
|
"type" => "Undo",
|
||||||
|
"object" => %{"type" => "EmojiReaction", "id" => reaction_activity_id},
|
||||||
|
"actor" => _actor,
|
||||||
|
"id" => id
|
||||||
|
} = data,
|
||||||
|
_options
|
||||||
|
) do
|
||||||
|
with actor <- Containment.get_actor(data),
|
||||||
|
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
|
||||||
|
{:ok, activity, _} <-
|
||||||
|
ActivityPub.unreact_with_emoji(actor, reaction_activity_id,
|
||||||
|
activity_id: id,
|
||||||
|
local: false
|
||||||
|
) do
|
||||||
|
{:ok, activity}
|
||||||
|
else
|
||||||
|
_e -> :error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{
|
%{
|
||||||
"type" => "Undo",
|
"type" => "Undo",
|
||||||
|
|
|
@ -359,6 +359,25 @@ test "it works for incoming emoji reactions" do
|
||||||
assert data["content"] == "👌"
|
assert data["content"] == "👌"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it works for incoming emoji reaction undos" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "hello"})
|
||||||
|
{:ok, reaction_activity, _object} = CommonAPI.react_with_emoji(activity.id, user, "👌")
|
||||||
|
|
||||||
|
data =
|
||||||
|
File.read!("test/fixtures/mastodon-undo-like.json")
|
||||||
|
|> Poison.decode!()
|
||||||
|
|> Map.put("object", reaction_activity.data["id"])
|
||||||
|
|> Map.put("actor", user.ap_id)
|
||||||
|
|
||||||
|
{:ok, activity} = Transmogrifier.handle_incoming(data)
|
||||||
|
|
||||||
|
assert activity.actor == user.ap_id
|
||||||
|
assert activity.data["id"] == data["id"]
|
||||||
|
assert activity.data["type"] == "Undo"
|
||||||
|
end
|
||||||
|
|
||||||
test "it returns an error for incoming unlikes wihout a like activity" do
|
test "it returns an error for incoming unlikes wihout a like activity" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "leave a like pls"})
|
||||||
|
@ -1116,7 +1135,6 @@ test "it inlines private announced objects" do
|
||||||
{:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
|
{:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
|
||||||
|
|
||||||
{:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
|
{:ok, modified} = Transmogrifier.prepare_outgoing(announce_activity.data)
|
||||||
object = modified["object"]
|
|
||||||
|
|
||||||
assert modified["object"]["content"] == "hey"
|
assert modified["object"]["content"] == "hey"
|
||||||
assert modified["object"]["actor"] == modified["object"]["attributedTo"]
|
assert modified["object"]["actor"] == modified["object"]["attributedTo"]
|
||||||
|
|
Loading…
Reference in New Issue