Cancellation of a follow request for a remote user
This commit is contained in:
parent
8c71f7e11a
commit
8b9742ecf5
|
@ -30,9 +30,24 @@ def changeset(%__MODULE__{} = following_relationship, attrs) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(%User{} = follower, %User{} = following) do
|
def get(%User{} = follower, %User{} = following) do
|
||||||
|
following_relationship =
|
||||||
__MODULE__
|
__MODULE__
|
||||||
|> where(follower_id: ^follower.id, following_id: ^following.id)
|
|> where(follower_id: ^follower.id, following_id: ^following.id)
|
||||||
|> Repo.one()
|
|> 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
|
end
|
||||||
|
|
||||||
def update(follower, following, "reject"), do: unfollow(follower, following)
|
def update(follower, following, "reject"), do: unfollow(follower, following)
|
||||||
|
@ -58,8 +73,8 @@ def follow(%User{} = follower, %User{} = following, state \\ "accept") do
|
||||||
|
|
||||||
def unfollow(%User{} = follower, %User{} = following) do
|
def unfollow(%User{} = follower, %User{} = following) do
|
||||||
case get(follower, following) do
|
case get(follower, following) do
|
||||||
nil -> {:ok, nil}
|
|
||||||
%__MODULE__{} = following_relationship -> Repo.delete(following_relationship)
|
%__MODULE__{} = following_relationship -> Repo.delete(following_relationship)
|
||||||
|
_ -> {:ok, nil}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -537,7 +537,7 @@ test "also unsubscribes a user" do
|
||||||
refute User.subscribed_to?(follower, followed)
|
refute User.subscribed_to?(follower, followed)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "cancels a pending follow" do
|
test "cancels a pending follow for a local user" do
|
||||||
follower = insert(:user)
|
follower = insert(:user)
|
||||||
followed = insert(:user, locked: true)
|
followed = insert(:user, locked: true)
|
||||||
|
|
||||||
|
@ -560,6 +560,30 @@ test "cancels a pending follow" do
|
||||||
}
|
}
|
||||||
} = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
|
} = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "cancels a pending follow for a remote user" do
|
||||||
|
follower = insert(:user)
|
||||||
|
followed = insert(:user, locked: true, local: false, ap_enabled: true)
|
||||||
|
|
||||||
|
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
|
||||||
|
CommonAPI.follow(follower, followed)
|
||||||
|
|
||||||
|
assert %{state: "pending"} = Pleroma.FollowingRelationship.get(follower, followed)
|
||||||
|
|
||||||
|
assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
|
||||||
|
|
||||||
|
assert Pleroma.FollowingRelationship.get(follower, followed) == nil
|
||||||
|
|
||||||
|
assert %{id: ^activity_id, data: %{"state" => "cancelled"}} =
|
||||||
|
Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed)
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
data: %{
|
||||||
|
"type" => "Undo",
|
||||||
|
"object" => %{"type" => "Follow", "state" => "cancelled"}
|
||||||
|
}
|
||||||
|
} = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "accept_follow_request/2" do
|
describe "accept_follow_request/2" do
|
||||||
|
|
Loading…
Reference in New Issue