user: add a workaround for situations where Pleroma may believe a followee is followed
authorWilliam Pitcock <nenolod@dereferenced.org>
Mon, 28 May 2018 16:42:18 +0000 (16:42 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Mon, 11 Jun 2018 22:15:53 +0000 (22:15 +0000)
this was caused by lack of Undo follows in the early days, and can likely be eventually removed

lib/pleroma/user.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex

index 9c0cc74551e935797994c63141a8b01fce085d37..1dcb68470d92adda90ad42a3f86652037e2dc932 100644 (file)
@@ -197,6 +197,14 @@ defmodule Pleroma.User do
     end
   end
 
+  def maybe_follow(%User{} = follower, %User{info: info} = followed) do
+    if not following?(follower, followed) do
+      follow(follower, followed)
+    else
+      {:ok, follower}
+    end
+  end
+
   def follow(%User{} = follower, %User{info: info} = followed) do
     ap_followers = followed.follower_address
 
index caff4ad86b89f0484148dd8f40b5375f88fa4807..922b83ed0814791a0f1e9a5fa4e93485826d028c 100644 (file)
@@ -499,7 +499,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
 
   def authorize_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
     with %User{} = follower <- Repo.get(User, id),
-         {:ok, follower} <- User.follow(follower, followed),
+         {:ok, follower} <- User.maybe_follow(follower, followed),
          %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
          {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "accept"),
          {:ok, _activity} <-