From 5afdd80c712462925a87c2d75ed08c6cb1063bd1 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 2 May 2021 19:27:34 +0200 Subject: [PATCH] Fix searching for persons Signed-off-by: Thomas Citharel --- lib/graphql/api/search.ex | 2 +- lib/graphql/resolvers/search.ex | 2 +- lib/mobilizon/actors/actors.ex | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/graphql/api/search.ex b/lib/graphql/api/search.ex index d652dcb6..090eccf1 100644 --- a/lib/graphql/api/search.ex +++ b/lib/graphql/api/search.ex @@ -46,7 +46,7 @@ defmodule Mobilizon.GraphQL.API.Search do actor_type: [result_type], radius: Map.get(args, :radius), location: Map.get(args, :location), - minimum_visibility: :public + minimum_visibility: Map.get(args, :minimum_visibility, :public) ], page, limit diff --git a/lib/graphql/resolvers/search.ex b/lib/graphql/resolvers/search.ex index b9a5b0b8..9d3a68ff 100644 --- a/lib/graphql/resolvers/search.ex +++ b/lib/graphql/resolvers/search.ex @@ -9,7 +9,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Search do Search persons """ def search_persons(_parent, %{page: page, limit: limit} = args, _resolution) do - Search.search_actors(args, page, limit, :Person) + Search.search_actors(Map.put(args, :minimum_visibility, :private), page, limit, :Person) end @doc """ diff --git a/lib/mobilizon/actors/actors.ex b/lib/mobilizon/actors/actors.ex index 82e8dbf2..41543270 100644 --- a/lib/mobilizon/actors/actors.ex +++ b/lib/mobilizon/actors/actors.ex @@ -500,6 +500,10 @@ defmodule Mobilizon.Actors do defp filter_suspended(query, true), do: where(query, [a], a.suspended) defp filter_suspended(query, false), do: where(query, [a], not a.suspended) + @spec filter_out_anonymous_actor_id(Ecto.Query.t(), integer() | String.t()) :: Ecto.Query.t() + defp filter_out_anonymous_actor_id(query, anonymous_actor_id), + do: where(query, [a], a.id != ^anonymous_actor_id) + @doc """ Returns the list of local actors by their username. """ @@ -527,12 +531,15 @@ defmodule Mobilizon.Actors do page \\ nil, limit \\ nil ) do + anonymous_actor_id = Mobilizon.Config.anonymous_actor_id() + Actor |> actor_by_username_or_name_query(term) |> actors_for_location(Keyword.get(options, :location), Keyword.get(options, :radius)) |> filter_by_types(Keyword.get(options, :actor_type, :Group)) |> filter_by_minimum_visibility(Keyword.get(options, :minimum_visibility, :public)) |> filter_suspended(false) + |> filter_out_anonymous_actor_id(anonymous_actor_id) |> Page.build_page(page, limit) end