fixed delete `Like` activity in remove user
authorMaksim Pechnikov <parallel588@gmail.com>
Tue, 7 Jul 2020 06:10:02 +0000 (09:10 +0300)
committerMaksim Pechnikov <parallel588@gmail.com>
Wed, 8 Jul 2020 06:06:23 +0000 (09:06 +0300)
lib/pleroma/web/activity_pub/side_effects.ex
test/tasks/user_test.exs

index 61feeae4d68fb4799634b58b03a0ceaad9c3800d..70746f341d0a9541d98aa5d0f01cbcf5f2cd579e 100644 (file)
@@ -209,14 +209,20 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
     {:ok, object}
   end
 
-  def handle_undoing(%{data: %{"type" => "Like"}} = object) do
-    with %Object{} = liked_object <- Object.get_by_ap_id(object.data["object"]),
-         {:ok, _} <- Utils.remove_like_from_object(object, liked_object),
-         {:ok, _} <- Repo.delete(object) do
-      :ok
+  defp undo_like(nil, object), do: delete_object(object)
+
+  defp undo_like(%Object{} = liked_object, object) do
+    with {:ok, _} <- Utils.remove_like_from_object(object, liked_object) do
+      delete_object(object)
     end
   end
 
+  def handle_undoing(%{data: %{"type" => "Like"}} = object) do
+    object.data["object"]
+    |> Object.get_by_ap_id()
+    |> undo_like(object)
+  end
+
   def handle_undoing(%{data: %{"type" => "EmojiReact"}} = object) do
     with %Object{} = reacted_object <- Object.get_by_ap_id(object.data["object"]),
          {:ok, _} <- Utils.remove_emoji_reaction_from_object(object, reacted_object),
@@ -246,6 +252,11 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
 
   def handle_undoing(object), do: {:error, ["don't know how to handle", object]}
 
+  @spec delete_object(Object.t()) :: :ok | {:error, Ecto.Changeset.t()}
+  defp delete_object(object) do
+    with {:ok, _} <- Repo.delete(object), do: :ok
+  end
+
   defp send_notifications(meta) do
     Keyword.get(meta, :notifications, [])
     |> Enum.each(fn notification ->
index 9220d23fcbaf0a4d2167c822eb3f5f9a523cc6b9..c962819db6f56128e8ff132f812e36a6c91aa5a8 100644 (file)
@@ -110,7 +110,30 @@ defmodule Mix.Tasks.Pleroma.UserTest do
 
     test "a remote user's create activity is deleted when the object has been pruned" do
       user = insert(:user)
+      user2 = insert(:user)
+
       {:ok, post} = CommonAPI.post(user, %{status: "uguu"})
+      {:ok, post2} = CommonAPI.post(user2, %{status: "test"})
+      obj = Object.normalize(post2)
+
+      {:ok, like_object, meta} = Pleroma.Web.ActivityPub.Builder.like(user, obj)
+
+      {:ok, like_activity, _meta} =
+        Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
+          like_object,
+          Keyword.put(meta, :local, true)
+        )
+
+      like_obj = Pleroma.Object.get_by_ap_id(like_activity.data["object"])
+
+      data =
+        Map.merge(like_activity.data, %{"object" => "tag:gnusocial.cc,2019-01-09:noticeId=210716"})
+
+      like_activity
+      |> Ecto.Changeset.change(data: data)
+      |> Repo.update()
+
+      Repo.delete(like_obj)
 
       clear_config([:instance, :federating], true)
 
@@ -127,6 +150,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
         assert %{deactivated: true} = User.get_by_nickname(user.nickname)
 
         assert called(Pleroma.Web.Federator.publish(:_))
+        refute Pleroma.Repo.get(Pleroma.Activity, like_activity.id)
       end
 
       refute Activity.get_by_id(post.id)