From c649ca89586ec83407b298c20f51a25318d777b9 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 22 Apr 2018 01:55:41 -0400 Subject: [PATCH 1/3] Rename make_unannounce_data helper to make_undo_data This makes it a bit more easier to adapt for unlikes as well in the future. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/activity_pub/utils.ex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index ace230804..0eb5829ef 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -142,7 +142,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def unannounce(%User{} = actor, %Object{} = object, local \\ true) do with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), - unannounce_data <- make_unannounce_data(actor, activity), + unannounce_data <- make_undo_data(actor, activity), {:ok, unannounce_activity} <- insert(unannounce_data, local), :ok <- maybe_federate(activity), {:ok, _activity} <- Repo.delete(activity), diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 9e2fa1fb2..d2a421ea4 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -279,9 +279,9 @@ defmodule Pleroma.Web.ActivityPub.Utils do end @doc """ - Make unannounce activity data for the given actor and object + Make undo activity data for the given actor and object """ - def make_unannounce_data( + def make_undo_data( %User{ap_id: ap_id} = user, %Activity{data: %{"id" => id, "context" => context}} = activity ) do From b1742eca4292f99ac256408acf6441d4f3eaa346 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 22 Apr 2018 19:42:28 -0400 Subject: [PATCH 2/3] Revert "Rename make_unannounce_data helper to make_undo_data" This reverts commit c649ca89586ec83407b298c20f51a25318d777b9. --- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- lib/pleroma/web/activity_pub/utils.ex | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 0eb5829ef..ace230804 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -142,7 +142,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do def unannounce(%User{} = actor, %Object{} = object, local \\ true) do with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), - unannounce_data <- make_undo_data(actor, activity), + unannounce_data <- make_unannounce_data(actor, activity), {:ok, unannounce_activity} <- insert(unannounce_data, local), :ok <- maybe_federate(activity), {:ok, _activity} <- Repo.delete(activity), diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index d2a421ea4..9e2fa1fb2 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -279,9 +279,9 @@ defmodule Pleroma.Web.ActivityPub.Utils do end @doc """ - Make undo activity data for the given actor and object + Make unannounce activity data for the given actor and object """ - def make_undo_data( + def make_unannounce_data( %User{ap_id: ap_id} = user, %Activity{data: %{"id" => id, "context" => context}} = activity ) do From 8c0806539c1eac776db0634e2888927f1dd2141d Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Sun, 22 Apr 2018 21:28:51 -0400 Subject: [PATCH 3/3] Embed announce activity data instead of linking to it --- lib/pleroma/web/activity_pub/activity_pub.ex | 9 +++++++-- lib/pleroma/web/activity_pub/utils.ex | 9 ++++++--- test/web/activity_pub/activity_pub_test.exs | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index ace230804..63d893039 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -140,9 +140,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - def unannounce(%User{} = actor, %Object{} = object, local \\ true) do + def unannounce( + %User{} = actor, + %Object{} = object, + local \\ true, + activity_id \\ nil + ) do with %Activity{} = activity <- get_existing_announce(actor.ap_id, object), - unannounce_data <- make_unannounce_data(actor, activity), + unannounce_data <- make_unannounce_data(actor, activity, activity_id), {:ok, unannounce_activity} <- insert(unannounce_data, local), :ok <- maybe_federate(activity), {:ok, _activity} <- Repo.delete(activity), diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 9e2fa1fb2..10cc044fe 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -283,16 +283,19 @@ defmodule Pleroma.Web.ActivityPub.Utils do """ def make_unannounce_data( %User{ap_id: ap_id} = user, - %Activity{data: %{"id" => id, "context" => context}} = activity + %Activity{data: %{"context" => context}} = activity, + activity_id ) do - %{ + data = %{ "type" => "Undo", "actor" => ap_id, - "object" => id, + "object" => activity.data, "to" => [user.follower_address, activity.data["actor"]], "cc" => ["https://www.w3.org/ns/activitystreams#Public"], "context" => context } + + if activity_id, do: Map.put(data, "id", activity_id), else: data end def add_announce_to_object(%Activity{data: %{"actor" => actor}}, object) do diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index e3258ed4e..208cc42d2 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -292,9 +292,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do assert unannounce_activity.data["to"] == [ User.ap_followers(user), announce_activity.data["actor"] - ] + ] assert unannounce_activity.data["type"] == "Undo" - assert unannounce_activity.data["object"] == announce_activity.data["id"] + assert unannounce_activity.data["object"] == announce_activity.data assert unannounce_activity.data["actor"] == user.ap_id assert unannounce_activity.data["context"] == announce_activity.data["context"]