Allow to search groups by location

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-08-05 16:44:08 +02:00
parent 3bae65374f
commit 3c077c59ad
18 changed files with 408 additions and 149 deletions

View File

@@ -15,20 +15,17 @@ defmodule Mobilizon.GraphQL.API.Search do
@doc """
Searches actors.
"""
@spec search_actors(String.t(), integer | nil, integer | nil, ActorType.t()) ::
@spec search_actors(map(), integer | nil, integer | nil, ActorType.t()) ::
{:ok, Page.t()} | {:error, String.t()}
def search_actors(search, page \\ 1, limit \\ 10, result_type) do
search = String.trim(search)
def search_actors(%{term: term} = args, page \\ 1, limit \\ 10, result_type) do
term = String.trim(term)
cond do
search == "" ->
{:error, "Search can't be empty"}
# Some URLs could be domain.tld/@username, so keep this condition above
# the `is_handle` function
is_url(search) ->
is_url(term) ->
# skip, if it's not an actor
case process_from_url(search) do
case process_from_url(term) do
%Page{total: _total, elements: _elements} = page ->
{:ok, page}
@@ -36,11 +33,17 @@ defmodule Mobilizon.GraphQL.API.Search do
{:ok, %{total: 0, elements: []}}
end
is_handle(search) ->
{:ok, process_from_username(search)}
is_handle(term) ->
{:ok, process_from_username(term)}
true ->
page = Actors.build_actors_by_username_or_name_page(search, [result_type], page, limit)
page =
Actors.build_actors_by_username_or_name_page(
Map.put(args, :term, term),
[result_type],
page,
limit
)
{:ok, page}
end