From 1452b2823fbd858f2b818c35ca1faedb0d222690 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Mon, 28 May 2018 16:42:18 +0000 Subject: [PATCH] user: add a workaround for situations where Pleroma may believe a followee is followed this was caused by lack of Undo follows in the early days, and can likely be eventually removed --- lib/pleroma/user.ex | 8 ++++++++ lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 9c0cc7455..1dcb68470 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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 diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index caff4ad86..922b83ed0 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -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} <- -- 2.45.2