diff options
author | Egor Kislitsyn <egor@kislitsyn.com> | 2020-02-06 16:47:15 +0400 |
---|---|---|
committer | Egor Kislitsyn <egor@kislitsyn.com> | 2020-02-06 18:02:33 +0400 |
commit | 8b9742ecf546c37695229d54f0a0b3ed4edd66e1 (patch) | |
tree | 4156b1f31a8c2c41056dd10df4b3f9d05170a0d3 /lib | |
parent | 8c71f7e11a377d92234c141ea50170485e773fdc (diff) | |
download | pleroma-8b9742ecf546c37695229d54f0a0b3ed4edd66e1.tar.gz pleroma-8b9742ecf546c37695229d54f0a0b3ed4edd66e1.zip |
Cancellation of a follow request for a remote user
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/following_relationship.ex | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/pleroma/following_relationship.ex b/lib/pleroma/following_relationship.ex index 0b0219b82..cc381af53 100644 --- a/lib/pleroma/following_relationship.ex +++ b/lib/pleroma/following_relationship.ex @@ -30,9 +30,24 @@ defmodule Pleroma.FollowingRelationship do end def get(%User{} = follower, %User{} = following) do - __MODULE__ - |> where(follower_id: ^follower.id, following_id: ^following.id) - |> Repo.one() + following_relationship = + __MODULE__ + |> where(follower_id: ^follower.id, following_id: ^following.id) + |> Repo.one() + + case {following_relationship, following.local} do + {nil, false} -> + case Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, following) do + %{data: %{"state" => state}} when state in ["pending", "accept"] -> + %{state: state} + + _ -> + nil + end + + {following_relationship, _} -> + following_relationship + end end def update(follower, following, "reject"), do: unfollow(follower, following) @@ -58,8 +73,8 @@ defmodule Pleroma.FollowingRelationship do def unfollow(%User{} = follower, %User{} = following) do case get(follower, following) do - nil -> {:ok, nil} %__MODULE__{} = following_relationship -> Repo.delete(following_relationship) + _ -> {:ok, nil} end end |