fix(follow-instances): Show correct error message when trying to follow already following actor

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2023-04-26 16:35:24 +02:00
parent 8543204bd9
commit d969c6648f
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 11 additions and 1 deletions

View file

@ -527,6 +527,12 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
Instances.refresh() Instances.refresh()
get_instance(parent, args, resolution) get_instance(parent, args, resolution)
{:error, :follow_pending} ->
{:error, dgettext("errors", "This instance is pending follow approval")}
{:error, :already_following} ->
{:error, dgettext("errors", "You are already following this instance")}
{:error, :http_error} -> {:error, :http_error} ->
{:error, dgettext("errors", "Unable to find an instance to follow at this address")} {:error, dgettext("errors", "Unable to find an instance to follow at this address")}

View file

@ -1226,12 +1226,16 @@ defmodule Mobilizon.Actors do
approved :: boolean | nil approved :: boolean | nil
) :: ) ::
{:ok, Follower.t()} {:ok, Follower.t()}
| {:error, :already_following | :followed_suspended | Ecto.Changeset.t()} | {:error,
:already_following | :follow_pending | :followed_suspended | Ecto.Changeset.t()}
def follow(%Actor{} = followed, %Actor{} = follower, url \\ nil, approved \\ true) do def follow(%Actor{} = followed, %Actor{} = follower, url \\ nil, approved \\ true) do
if followed.suspended do if followed.suspended do
{:error, :followed_suspended} {:error, :followed_suspended}
else else
case check_follow(follower, followed) do case check_follow(follower, followed) do
%Follower{approved: false} ->
{:error, :follow_pending}
%Follower{} -> %Follower{} ->
{:error, :already_following} {:error, :already_following}