Add follow_requests_outstanding_since?/3 to Pleroma.Activity
authorMark Felder <feld@feld.me>
Fri, 19 Feb 2021 21:16:55 +0000 (15:16 -0600)
committerMark Felder <feld@feld.me>
Tue, 30 Mar 2021 16:10:44 +0000 (11:10 -0500)
lib/pleroma/activity.ex

index d594038849bbd6ed68bd7f774adb52cacec7b911..b0f1a900d78cfa26390e5ad2972cfa169aa89851 100644 (file)
@@ -345,6 +345,20 @@ defmodule Pleroma.Activity do
     |> Repo.all()
   end
 
+  def follow_requests_outstanding_since?(
+        %User{ap_id: follower_id},
+        %User{ap_id: followee_id},
+        since_datetime
+      ) do
+    followee_id
+    |> Queries.by_object_id()
+    |> Queries.by_type("Follow")
+    |> where([a], a.inserted_at > ^since_datetime)
+    |> where([a], fragment("? ->> 'state' != 'accept'", a.data))
+    |> where([a], a.actor == ^follower_id)
+    |> Repo.exists?()
+  end
+
   def restrict_deactivated_users(query) do
     deactivated_users =
       from(u in User.Query.build(%{deactivated: true}), select: u.ap_id)