From 687db1bc3a13d3303865a104f0475a6fc4671037 Mon Sep 17 00:00:00 2001 From: Francis Dinh Date: Wed, 18 Apr 2018 03:39:42 -0400 Subject: [PATCH] Expose unannounce activity so that it can be tested --- lib/pleroma/web/activity_pub/activity_pub.ex | 6 +++--- lib/pleroma/web/activity_pub/utils.ex | 4 ++-- .../web/mastodon_api/mastodon_api_controller.ex | 2 +- test/web/activity_pub/activity_pub_test.exs | 15 ++++++++++++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 2239da472..3b918e28f 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -142,11 +142,11 @@ 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), - {:ok, _unannounce_activity} <- insert(unannounce_data, local), + unannounce_data <- make_unannounce_data(actor, object), + {:ok, unannounce_activity} <- insert(unannounce_data, local), {:ok, _activity} <- Repo.delete(activity), {:ok, object} <- remove_announce_from_object(activity, object) do - {:ok, object} + {:ok, unannounce_activity, object} else _e -> {:ok, object} end diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index 9e2fa1fb2..1f740eda5 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -283,13 +283,13 @@ defmodule Pleroma.Web.ActivityPub.Utils do """ def make_unannounce_data( %User{ap_id: ap_id} = user, - %Activity{data: %{"id" => id, "context" => context}} = activity + %Object{data: %{"id" => id, "context" => context}} = object ) do %{ "type" => "Undo", "actor" => ap_id, "object" => id, - "to" => [user.follower_address, activity.data["actor"]], + "to" => [user.follower_address, object.data["actor"]], "cc" => ["https://www.w3.org/ns/activitystreams#Public"], "context" => context } diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 6ddfc8b75..c01552410 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -297,7 +297,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end def unreblog_status(%{assigns: %{user: user}} = conn, %{"id" => ap_id_or_id}) do - with {:ok, %{data: %{"id" => id}}} = CommonAPI.unrepeat(ap_id_or_id, user), + with {:ok, _, %{data: %{"id" => id}}} = CommonAPI.unrepeat(ap_id_or_id, user), %Activity{} = activity <- Activity.get_create_activity_by_object_ap_id(id) do render(conn, StatusView, "status.json", %{activity: activity, for: user, as: :activity}) end diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 84f844322..85a6aecf0 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -278,15 +278,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do user = insert(:user) # Unannouncing an object that is not announced does nothing - {:ok, object} = ActivityPub.unannounce(user, object) - assert object.data["announcement_count"] == 0 + #{:ok, object} = ActivityPub.unannounce(user, object) + #assert object.data["announcement_count"] == 0 {:ok, announce_activity, object} = ActivityPub.announce(user, object) assert object.data["announcement_count"] == 1 - {:ok, object} = ActivityPub.unannounce(user, object) + {:ok, unannounce_activity, object} = ActivityPub.unannounce(user, object) assert object.data["announcement_count"] == 0 + assert unannounce_activity.data["to"] == [ + User.ap_followers(user), + note_activity.data["actor"] + ] + assert unannounce_activity.data["type"] == "Undo" + assert unannounce_activity.data["object"] == object.data["id"] + assert unannounce_activity.data["actor"] == user.ap_id + assert unannounce_activity.data["context"] == object.data["context"] + assert Repo.get(Activity, announce_activity.id) == nil end end