From 1319985047e7e07ba180448e547bde64faa9fba8 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 29 Dec 2021 14:59:33 +0100 Subject: [PATCH] Rename Mobilizon.Actors.is_following/2 to check_follow/2 Signed-off-by: Thomas Citharel --- lib/graphql/api/follows.ex | 4 +-- lib/mobilizon/actors/actors.ex | 8 +++--- .../transmogrifier/follow_test.exs | 28 +++++++++---------- .../activity_pub/transmogrifier/undo_test.exs | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/graphql/api/follows.ex b/lib/graphql/api/follows.ex index f30219fe6..05c87b0b1 100644 --- a/lib/graphql/api/follows.ex +++ b/lib/graphql/api/follows.ex @@ -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." ) - case Actors.is_following(follower, followed) do + case Actors.check_follow(follower, followed) do %Follower{approved: false} = follow -> Actions.Accept.accept( :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." ) - case Actors.is_following(follower, followed) do + case Actors.check_follow(follower, followed) do %Follower{approved: false} -> {:error, "Follow already rejected"} diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index b67b85e11..b264c4dc4 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -1176,7 +1176,7 @@ defmodule Mobilizon.Actors do if followed.suspended do {:error, :followed_suspended} else - case is_following(follower, followed) do + case check_follow(follower, followed) do %Follower{} -> {:error, :already_following} @@ -1202,7 +1202,7 @@ defmodule Mobilizon.Actors do @spec unfollow(Actor.t(), Actor.t()) :: {:ok, Follower.t()} | {:error, Ecto.Changeset.t() | String.t()} 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} -> delete_follower(follow) @@ -1214,8 +1214,8 @@ defmodule Mobilizon.Actors do @doc """ Checks whether an actor is following another actor. """ - @spec is_following(Actor.t(), Actor.t()) :: Follower.t() | nil - def is_following(%Actor{} = follower_actor, %Actor{} = followed_actor) do + @spec check_follow(Actor.t(), Actor.t()) :: Follower.t() | nil + def check_follow(%Actor{} = follower_actor, %Actor{} = followed_actor) do get_follower_by_followed_and_following(followed_actor, follower_actor) end diff --git a/test/federation/activity_pub/transmogrifier/follow_test.exs b/test/federation/activity_pub/transmogrifier/follow_test.exs index 285fea0cb..925bdd82c 100644 --- a/test/federation/activity_pub/transmogrifier/follow_test.exs +++ b/test/federation/activity_pub/transmogrifier/follow_test.exs @@ -36,7 +36,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do end) =~ "Only group and instances can be followed" 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 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" 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 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["type"] == "Follow" # 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 @@ -106,10 +106,10 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do follower = insert(:actor) 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) - assert Actors.is_following(follower, followed) + assert Actors.check_follow(follower, followed) 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) - assert Actors.is_following(follower, followed) + assert Actors.check_follow(follower, followed) end test "it works for incoming accepts which were pre-accepted" do follower = insert(:actor) 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) - assert Actors.is_following(follower, followed) + assert Actors.check_follow(follower, followed) 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) - assert Actors.is_following(follower, followed) + assert Actors.check_follow(follower, followed) end 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) - assert Actors.is_following(follower, followed) + assert Actors.check_follow(follower, followed) end 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) - refute Actors.is_following(follower, followed) + refute Actors.check_follow(follower, followed) end end @@ -228,7 +228,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do {:ok, follower} = Actors.get_actor_by_url(follower.url) - refute Actors.is_following(follower, followed) + refute Actors.check_follow(follower, followed) end 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) - assert Actors.is_following(follower, followed) + assert Actors.check_follow(follower, followed) reject_data = 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) - refute Actors.is_following(follower, followed) + refute Actors.check_follow(follower, followed) end end end diff --git a/test/federation/activity_pub/transmogrifier/undo_test.exs b/test/federation/activity_pub/transmogrifier/undo_test.exs index 74d9b30f6..35632690c 100644 --- a/test/federation/activity_pub/transmogrifier/undo_test.exs +++ b/test/federation/activity_pub/transmogrifier/undo_test.exs @@ -82,7 +82,7 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.UndoTest do assert data["actor"] == "https://social.tcit.fr/users/tcit" {:ok, followed} = Actors.get_actor_by_url(data["actor"]) - refute Actors.is_following(followed, actor) + refute Actors.check_follow(followed, actor) end end end