aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/following_relationship.ex21
-rw-r--r--lib/pleroma/user.ex22
2 files changed, 23 insertions, 20 deletions
diff --git a/lib/pleroma/following_relationship.ex b/lib/pleroma/following_relationship.ex
index cc381af53..b8cb3bf03 100644
--- a/lib/pleroma/following_relationship.ex
+++ b/lib/pleroma/following_relationship.ex
@@ -30,24 +30,9 @@ defmodule Pleroma.FollowingRelationship do
end
def get(%User{} = follower, %User{} = following) do
- 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
+ __MODULE__
+ |> where(follower_id: ^follower.id, following_id: ^following.id)
+ |> Repo.one()
end
def update(follower, following, "reject"), do: unfollow(follower, following)
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 398c91cf3..5ea36fea3 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -652,8 +652,8 @@ defmodule Pleroma.User do
end
def unfollow(%User{} = follower, %User{} = followed) do
- case FollowingRelationship.get(follower, followed) do
- %{state: state} when state in ["accept", "pending"] ->
+ case get_follow_state(follower, followed) do
+ state when state in ["accept", "pending"] ->
FollowingRelationship.unfollow(follower, followed)
{:ok, followed} = update_follower_count(followed)
@@ -671,6 +671,24 @@ defmodule Pleroma.User do
defdelegate following?(follower, followed), to: FollowingRelationship
+ def get_follow_state(%User{} = follower, %User{} = following) do
+ following_relationship = FollowingRelationship.get(follower, following)
+
+ case {following_relationship, following.local} do
+ {nil, false} ->
+ case Utils.fetch_latest_follow(follower, following) do
+ %{data: %{"state" => state}} when state in ["pending", "accept"] -> state
+ _ -> nil
+ end
+
+ {%{state: state}, _} ->
+ state
+
+ {nil, _} ->
+ nil
+ end
+ end
+
def locked?(%User{} = user) do
user.locked || false
end