From 28d5b40d0afddaca6797e2b72c2e89624e68f967 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Tue, 5 Mar 2019 23:15:22 +0100 Subject: [PATCH] Add handling of objects not in database --- lib/pleroma/web/activity_pub/activity_pub.ex | 10 ++++++++-- test/web/activity_pub/activity_pub_test.exs | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 98639883e..7e7a43c55 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -311,8 +311,14 @@ def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ tru user = User.get_cached_by_ap_id(actor) to = - object.data["to"] || [] ++ object.data["cc"] || - [] ++ [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + case Object.get_cached_by_ap_id(id) do + nil -> + [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + + object -> + object.data["to"] || [] ++ object.data["cc"] || + [] ++ [user.follower_address, "https://www.w3.org/ns/activitystreams#Public"] + end data = %{ "type" => "Delete", diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index e607c7f4d..10c5258d0 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -691,12 +691,23 @@ test "decrements user note count only for public activities" do user = Repo.get(User, user.id) assert user.info.note_count == 10 end - + test "it creates a delete activity and checks that it is also sent to users mentioned by the deleted object" do user = insert(:user) note = insert(:note_activity) - object = Object.get_by_ap_id(note.data["object"]["id"]) - object = Kernel.put_in(object.data["to"], [user.ap_id]) + + {:ok, object} = + Object.get_by_ap_id(note.data["object"]["id"]) + |> Object.change(%{ + data: %{ + "actor" => note.data["object"]["actor"], + "id" => note.data["object"]["id"], + "to" => [user.ap_id], + "type" => "Note" + } + }) + |> Object.update_and_set_cache() + {:ok, delete} = ActivityPub.delete(object) assert user.ap_id in delete.data["to"]