diff options
author | Egor Kislitsyn <egor@kislitsyn.com> | 2020-02-04 20:35:32 +0400 |
---|---|---|
committer | Egor Kislitsyn <egor@kislitsyn.com> | 2020-02-05 20:22:15 +0400 |
commit | 8c71f7e11a377d92234c141ea50170485e773fdc (patch) | |
tree | 9fc6579f7a07e92a3bd8dd9d2d6aee1f914fa6c3 /lib/pleroma/user.ex | |
parent | c27d1d65bfd60effdb45359697141c136e156177 (diff) | |
download | pleroma-8c71f7e11a377d92234c141ea50170485e773fdc.tar.gz |
Add support for cancellation of a follow request
Diffstat (limited to 'lib/pleroma/user.ex')
-rw-r--r-- | lib/pleroma/user.ex | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 3c86cdb38..398c91cf3 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -647,20 +647,25 @@ defmodule Pleroma.User do end end + def unfollow(%User{ap_id: ap_id}, %User{ap_id: ap_id}) do + {:error, "Not subscribed!"} + end + def unfollow(%User{} = follower, %User{} = followed) do - if following?(follower, followed) and follower.ap_id != followed.ap_id do - FollowingRelationship.unfollow(follower, followed) + case FollowingRelationship.get(follower, followed) do + %{state: state} when state in ["accept", "pending"] -> + FollowingRelationship.unfollow(follower, followed) + {:ok, followed} = update_follower_count(followed) - {:ok, followed} = update_follower_count(followed) + {:ok, follower} = + follower + |> update_following_count() + |> set_cache() - {:ok, follower} = - follower - |> update_following_count() - |> set_cache() + {:ok, follower, Utils.fetch_latest_follow(follower, followed)} - {:ok, follower, Utils.fetch_latest_follow(follower, followed)} - else - {:error, "Not subscribed!"} + nil -> + {:error, "Not subscribed!"} end end |