From 2bbec33c7112ede3f93a7d35e9d5f3ac5a31ce05 Mon Sep 17 00:00:00 2001 From: Maxim Filippov Date: Tue, 25 Dec 2018 00:29:13 +0300 Subject: [PATCH] Fix failing tests --- lib/pleroma/activity.ex | 15 +++++++++------ lib/pleroma/notification.ex | 10 +++++++--- lib/pleroma/web/activity_pub/transmogrifier.ex | 3 ++- test/activity_test.exs | 2 +- .../incoming_documents/delete_handling_test.exs | 6 +++--- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 0845233ee..be04363aa 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -108,17 +108,20 @@ def get_tombstone(%Activity{data: data}, deleted \\ DateTime.utc_now()) do %{ id: data["id"], context: data["context"], - type: "tombstone", + type: "Tombstone", published: data["published"], deleted: deleted } end def swap_data_with_tombstone(activity) do - tombstone = get_tombstone(activity) - - activity - |> change(%{data: tombstone}) - |> Repo.update() + with tombstone = get_tombstone(activity), + Notification.clear(activity), + {:ok, changed_activity} = + activity + |> change(%{data: tombstone}) + |> Repo.update() do + {:ok, changed_activity} + end end end diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 47f6b6ee7..457cba935 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -75,10 +75,14 @@ def get(%{id: user_id} = _user, id) do end end - def clear(user) do - query = from(n in Notification, where: n.user_id == ^user.id) + def clear(%User{} = user) do + from(n in Notification, where: n.user_id == ^user.id) + |> Repo.delete_all() + end - Repo.delete_all(query) + def clear(%Activity{} = activity) do + from(n in Notification, where: n.activity_id == ^activity.id) + |> Repo.delete_all() end def dismiss(%{id: user_id} = _user, id) do diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index e6af4b211..87514870d 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -586,7 +586,8 @@ def get_obj_helper(id) do end def set_reply_to_uri(%{"inReplyTo" => inReplyTo} = object) do - with false <- String.starts_with?(inReplyTo, "http"), + with false <- is_nil(inReplyTo), + false <- String.starts_with?(inReplyTo, "http"), {:ok, %{data: replied_to_object}} <- get_obj_helper(inReplyTo) do Map.put(object, "inReplyTo", replied_to_object["external_url"] || inReplyTo) else diff --git a/test/activity_test.exs b/test/activity_test.exs index c47fe39da..dd11323b5 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -31,7 +31,7 @@ test "returns tombstone" do deleted = DateTime.utc_now() assert Pleroma.Activity.get_tombstone(activity, deleted) == %{ - id: activity.data["object"]["id"], + id: activity.data["id"], context: activity.data["context"], type: "Tombstone", published: activity.data["published"], diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs index 1e041e5b0..4e9c0f90f 100644 --- a/test/web/ostatus/incoming_documents/delete_handling_test.exs +++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs @@ -23,9 +23,9 @@ test "it removes the mentioned activity" do {:ok, [delete]} = OStatus.handle_incoming(incoming) - refute Repo.get(Activity, note.id) - refute Repo.get(Activity, like.id) - refute Object.get_by_ap_id(note.data["object"]["id"]) + assert Repo.get(Activity, note.id).data["type"] == "Tombstone" + assert Repo.get(Activity, like.id).data["type"] == "Tombstone" + assert Object.get_by_ap_id(note.data["object"]["id"]).data["type"] == "Tombstone" assert Repo.get(Activity, second_note.id) assert Object.get_by_ap_id(second_note.data["object"]["id"])