Allow to search groups by location
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user