activitypub: utils: update the state of *any* pending follow relationship that matche...
authorWilliam Pitcock <nenolod@dereferenced.org>
Tue, 29 Jan 2019 12:21:02 +0000 (12:21 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Tue, 29 Jan 2019 12:21:02 +0000 (12:21 +0000)
lib/pleroma/web/activity_pub/utils.ex

index e40d05fcdd9161e1bd49ccda6b1ed166f887a3dd..3b0cdfe711baa33dad6f56331d9514614930a83b 100644 (file)
@@ -316,6 +316,25 @@ defmodule Pleroma.Web.ActivityPub.Utils do
   @doc """
   Updates a follow activity's state (for locked accounts).
   """
+  def update_follow_state(
+        %Activity{data: %{"actor" => actor, "object" => object, "state" => "pending"}} = activity,
+        state
+      ) do
+    try do
+      Ecto.Adapters.SQL.query!(
+        Repo,
+        "UPDATE activities SET data = jsonb_set(data, '{state}', $1) WHERE data->>'type' = 'Follow' AND data->>'actor' = $2 AND data->>'object' = $3 AND data->>'state' = 'pending'",
+        [state, actor, object]
+      )
+
+      activity = Repo.get(Activity, activity.id)
+      {:ok, activity}
+    rescue
+      e ->
+        {:error, e}
+    end
+  end
+
   def update_follow_state(%Activity{} = activity, state) do
     with new_data <-
            activity.data