Rename Mobilizon.Actors.is_following/2 to check_follow/2

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-12-29 14:59:33 +01:00
parent bc6cec45fa
commit 1319985047
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
4 changed files with 21 additions and 21 deletions

View file

@ -41,7 +41,7 @@ defmodule Mobilizon.GraphQL.API.Follows do
"We're trying to accept a follow: #{followed_url} is accepting #{follower_url} follow request." "We're trying to accept a follow: #{followed_url} is accepting #{follower_url} follow request."
) )
case Actors.is_following(follower, followed) do case Actors.check_follow(follower, followed) do
%Follower{approved: false} = follow -> %Follower{approved: false} = follow ->
Actions.Accept.accept( Actions.Accept.accept(
:follow, :follow,
@ -68,7 +68,7 @@ defmodule Mobilizon.GraphQL.API.Follows do
"We're trying to reject a follow: #{followed_url} is rejecting #{follower_url} follow request." "We're trying to reject a follow: #{followed_url} is rejecting #{follower_url} follow request."
) )
case Actors.is_following(follower, followed) do case Actors.check_follow(follower, followed) do
%Follower{approved: false} -> %Follower{approved: false} ->
{:error, "Follow already rejected"} {:error, "Follow already rejected"}

View file

@ -1176,7 +1176,7 @@ defmodule Mobilizon.Actors do
if followed.suspended do if followed.suspended do
{:error, :followed_suspended} {:error, :followed_suspended}
else else
case is_following(follower, followed) do case check_follow(follower, followed) do
%Follower{} -> %Follower{} ->
{:error, :already_following} {:error, :already_following}
@ -1202,7 +1202,7 @@ defmodule Mobilizon.Actors do
@spec unfollow(Actor.t(), Actor.t()) :: @spec unfollow(Actor.t(), Actor.t()) ::
{:ok, Follower.t()} | {:error, Ecto.Changeset.t() | String.t()} {:ok, Follower.t()} | {:error, Ecto.Changeset.t() | String.t()}
def unfollow(%Actor{} = followed, %Actor{} = follower) do def unfollow(%Actor{} = followed, %Actor{} = follower) do
case {:already_following, is_following(follower, followed)} do case {:already_following, check_follow(follower, followed)} do
{:already_following, %Follower{} = follow} -> {:already_following, %Follower{} = follow} ->
delete_follower(follow) delete_follower(follow)
@ -1214,8 +1214,8 @@ defmodule Mobilizon.Actors do
@doc """ @doc """
Checks whether an actor is following another actor. Checks whether an actor is following another actor.
""" """
@spec is_following(Actor.t(), Actor.t()) :: Follower.t() | nil @spec check_follow(Actor.t(), Actor.t()) :: Follower.t() | nil
def is_following(%Actor{} = follower_actor, %Actor{} = followed_actor) do def check_follow(%Actor{} = follower_actor, %Actor{} = followed_actor) do
get_follower_by_followed_and_following(followed_actor, follower_actor) get_follower_by_followed_and_following(followed_actor, follower_actor)
end end

View file

@ -36,7 +36,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
end) =~ "Only group and instances can be followed" end) =~ "Only group and instances can be followed"
actor = Actors.get_actor_with_preload(actor.id) actor = Actors.get_actor_with_preload(actor.id)
refute Actors.is_following(Actors.get_actor_by_url!(data["actor"], true), actor) refute Actors.check_follow(Actors.get_actor_by_url!(data["actor"], true), actor)
end end
test "it works for incoming follow requests" do test "it works for incoming follow requests" do
@ -68,7 +68,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
assert data["id"] == "https://social.tcit.fr/users/tcit#follows/2" assert data["id"] == "https://social.tcit.fr/users/tcit#follows/2"
actor = Actors.get_actor_with_preload(actor.id) actor = Actors.get_actor_with_preload(actor.id)
assert Actors.is_following(Actors.get_actor_by_url!(data["actor"], true), actor) assert Actors.check_follow(Actors.get_actor_by_url!(data["actor"], true), actor)
end end
test "it rejects activities without a valid ID" do test "it rejects activities without a valid ID" do
@ -97,7 +97,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
# assert data["actor"] == "https://hubzilla.example.org/channel/kaniini" # assert data["actor"] == "https://hubzilla.example.org/channel/kaniini"
# assert data["type"] == "Follow" # assert data["type"] == "Follow"
# assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2" # assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
# assert User.is_following(User.get_by_ap_id(data["actor"]), user) # assert User.check_follow(User.get_by_ap_id(data["actor"]), user)
# end # end
end end
@ -106,10 +106,10 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
follower = insert(:actor) follower = insert(:actor)
followed = insert(:group, manually_approves_followers: false) followed = insert(:group, manually_approves_followers: false)
refute Actors.is_following(follower, followed) refute Actors.check_follow(follower, followed)
{:ok, follow_activity, _} = Actions.Follow.follow(follower, followed) {:ok, follow_activity, _} = Actions.Follow.follow(follower, followed)
assert Actors.is_following(follower, followed) assert Actors.check_follow(follower, followed)
follow_object_id = follow_activity.data["id"] follow_object_id = follow_activity.data["id"]
@ -131,17 +131,17 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
{:ok, follower} = Actors.get_actor_by_url(follower.url) {:ok, follower} = Actors.get_actor_by_url(follower.url)
assert Actors.is_following(follower, followed) assert Actors.check_follow(follower, followed)
end end
test "it works for incoming accepts which were pre-accepted" do test "it works for incoming accepts which were pre-accepted" do
follower = insert(:actor) follower = insert(:actor)
followed = insert(:group, manually_approves_followers: true) followed = insert(:group, manually_approves_followers: true)
refute Actors.is_following(follower, followed) refute Actors.check_follow(follower, followed)
{:ok, follow_activity, _} = Actions.Follow.follow(follower, followed) {:ok, follow_activity, _} = Actions.Follow.follow(follower, followed)
assert Actors.is_following(follower, followed) assert Actors.check_follow(follower, followed)
follow_object_id = follow_activity.data["id"] follow_object_id = follow_activity.data["id"]
@ -166,7 +166,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
{:ok, follower} = Actors.get_actor_by_url(follower.url) {:ok, follower} = Actors.get_actor_by_url(follower.url)
assert Actors.is_following(follower, followed) assert Actors.check_follow(follower, followed)
end end
test "it works for incoming accepts which are referenced by IRI only" do test "it works for incoming accepts which are referenced by IRI only" do
@ -188,7 +188,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
{:ok, follower} = Actors.get_actor_by_url(follower.url) {:ok, follower} = Actors.get_actor_by_url(follower.url)
assert Actors.is_following(follower, followed) assert Actors.check_follow(follower, followed)
end end
test "it fails for incoming accepts which cannot be correlated" do test "it fails for incoming accepts which cannot be correlated" do
@ -207,7 +207,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
{:ok, follower} = Actors.get_actor_by_url(follower.url) {:ok, follower} = Actors.get_actor_by_url(follower.url)
refute Actors.is_following(follower, followed) refute Actors.check_follow(follower, followed)
end end
end end
@ -228,7 +228,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
{:ok, follower} = Actors.get_actor_by_url(follower.url) {:ok, follower} = Actors.get_actor_by_url(follower.url)
refute Actors.is_following(follower, followed) refute Actors.check_follow(follower, followed)
end end
test "it works for incoming rejects which are referenced by IRI only" do test "it works for incoming rejects which are referenced by IRI only" do
@ -237,7 +237,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
{:ok, follow_activity, _} = Actions.Follow.follow(follower, followed) {:ok, follow_activity, _} = Actions.Follow.follow(follower, followed)
assert Actors.is_following(follower, followed) assert Actors.check_follow(follower, followed)
reject_data = reject_data =
File.read!("test/fixtures/mastodon-reject-activity.json") File.read!("test/fixtures/mastodon-reject-activity.json")
@ -247,7 +247,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do
{:ok, %Activity{data: _}, _} = Transmogrifier.handle_incoming(reject_data) {:ok, %Activity{data: _}, _} = Transmogrifier.handle_incoming(reject_data)
refute Actors.is_following(follower, followed) refute Actors.check_follow(follower, followed)
end end
end end
end end

View file

@ -82,7 +82,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.UndoTest do
assert data["actor"] == "https://social.tcit.fr/users/tcit" assert data["actor"] == "https://social.tcit.fr/users/tcit"
{:ok, followed} = Actors.get_actor_by_url(data["actor"]) {:ok, followed} = Actors.get_actor_by_url(data["actor"])
refute Actors.is_following(followed, actor) refute Actors.check_follow(followed, actor)
end end
end end
end end