Allow updating accepted follow activities in Web.ActivityPub.Utils.update_follow_stat...
authorTusooa Zhu <tusooa@kazv.moe>
Fri, 17 Dec 2021 19:17:51 +0000 (14:17 -0500)
committerTusooa Zhu <tusooa@kazv.moe>
Fri, 17 Dec 2021 19:17:51 +0000 (14:17 -0500)
Mastodon uses the Reject activity also for the purpose of removing
a follower, in addition to reject a follow request. We should
also update the original Follow activity in this case.

lib/pleroma/web/activity_pub/utils.ex
test/pleroma/web/activity_pub/utils_test.exs

index 1df53f79ad75f20dc1f8b7ef193e7c52d1d8b9a9..c1f6b2b49838d6bbcf6c07f0002f496e553ce397 100644 (file)
@@ -446,7 +446,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
     |> Activity.Queries.by_type()
     |> Activity.Queries.by_actor(actor)
     |> Activity.Queries.by_object_id(object)
-    |> where(fragment("data->>'state' = 'pending'"))
+    |> where(fragment("data->>'state' = 'pending'") or fragment("data->>'state' = 'accept'"))
     |> update(set: [data: fragment("jsonb_set(data, '{state}', ?)", ^state)])
     |> Repo.update_all([])
 
index ee3e1014e29e1d550ad40a8b76ffca7077e8f8ca..62dc02f61fe66105445ea62ac3c7c4bf5857e940 100644 (file)
@@ -213,6 +213,20 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
       assert refresh_record(follow_activity).data["state"] == "accept"
       assert refresh_record(follow_activity_two).data["state"] == "accept"
     end
+
+    test "also updates the state of accepted follows" do
+      user = insert(:user)
+      follower = insert(:user)
+
+      {:ok, _, _, follow_activity} = CommonAPI.follow(follower, user)
+      {:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user)
+
+      {:ok, follow_activity_two} =
+        Utils.update_follow_state_for_all(follow_activity_two, "reject")
+
+      assert refresh_record(follow_activity).data["state"] == "reject"
+      assert refresh_record(follow_activity_two).data["state"] == "reject"
+    end
   end
 
   describe "update_follow_state/2" do