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
|
||||
|
||||
@@ -8,15 +8,15 @@ defmodule Mobilizon.GraphQL.Resolvers.Search do
|
||||
@doc """
|
||||
Search persons
|
||||
"""
|
||||
def search_persons(_parent, %{search: search, page: page, limit: limit}, _resolution) do
|
||||
Search.search_actors(search, page, limit, :Person)
|
||||
def search_persons(_parent, %{page: page, limit: limit} = args, _resolution) do
|
||||
Search.search_actors(args, page, limit, :Person)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Search groups
|
||||
"""
|
||||
def search_groups(_parent, %{search: search, page: page, limit: limit}, _resolution) do
|
||||
Search.search_actors(search, page, limit, :Group)
|
||||
def search_groups(_parent, %{page: page, limit: limit} = args, _resolution) do
|
||||
Search.search_actors(args, page, limit, :Group)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
@@ -5,6 +5,9 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
||||
|
||||
use Absinthe.Schema.Notation
|
||||
|
||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||
|
||||
alias Mobilizon.Addresses
|
||||
alias Mobilizon.GraphQL.Resolvers.{Discussion, Group, Member, Post, Resource, Todos}
|
||||
alias Mobilizon.GraphQL.Schema
|
||||
|
||||
@@ -29,11 +32,20 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
||||
description: "Whether the actors manually approves followers"
|
||||
)
|
||||
|
||||
field(:visibility, :group_visibility,
|
||||
description: "Whether the group can be found and/or promoted"
|
||||
)
|
||||
|
||||
field(:suspended, :boolean, description: "If the actor is suspended")
|
||||
|
||||
field(:avatar, :picture, description: "The actor's avatar picture")
|
||||
field(:banner, :picture, description: "The actor's banner picture")
|
||||
|
||||
field(:physical_address, :address,
|
||||
resolve: dataloader(Addresses),
|
||||
description: "The type of the event's address"
|
||||
)
|
||||
|
||||
# These one should have a privacy setting
|
||||
field(:following, list_of(:follower), description: "List of followings")
|
||||
field(:followers, list_of(:follower), description: "List of followers")
|
||||
@@ -155,6 +167,8 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
||||
"The banner for the group, either as an object or directly the ID of an existing Picture"
|
||||
)
|
||||
|
||||
arg(:physical_address, :address_input)
|
||||
|
||||
resolve(&Group.create_group/3)
|
||||
end
|
||||
|
||||
@@ -165,6 +179,8 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
||||
arg(:name, :string, description: "The displayed name for the group")
|
||||
arg(:summary, :string, description: "The summary for the group", default_value: "")
|
||||
|
||||
arg(:visibility, :group_visibility, description: "The visibility for the group")
|
||||
|
||||
arg(:avatar, :picture_input,
|
||||
description:
|
||||
"The avatar for the group, either as an object or directly the ID of an existing Picture"
|
||||
@@ -175,6 +191,8 @@ defmodule Mobilizon.GraphQL.Schema.Actors.GroupType do
|
||||
"The banner for the group, either as an object or directly the ID of an existing Picture"
|
||||
)
|
||||
|
||||
arg(:physical_address, :address_input)
|
||||
|
||||
resolve(&Group.update_group/3)
|
||||
end
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
object :search_queries do
|
||||
@desc "Search persons"
|
||||
field :search_persons, :persons do
|
||||
arg(:search, non_null(:string))
|
||||
arg(:term, :string, default_value: "")
|
||||
arg(:page, :integer, default_value: 1)
|
||||
arg(:limit, :integer, default_value: 10)
|
||||
|
||||
@@ -36,7 +36,9 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
|
||||
@desc "Search groups"
|
||||
field :search_groups, :groups do
|
||||
arg(:search, non_null(:string))
|
||||
arg(:term, :string, default_value: "")
|
||||
arg(:location, :string, description: "A geohash for coordinates")
|
||||
arg(:radius, :float, default_value: 50)
|
||||
arg(:page, :integer, default_value: 1)
|
||||
arg(:limit, :integer, default_value: 10)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user