Improve searching for group actors

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-11-06 10:09:54 +01:00
parent 4fc044c595
commit 4de39d5850
8 changed files with 97 additions and 41 deletions

View File

@@ -40,13 +40,15 @@ defmodule Mobilizon.GraphQL.API.Search do
true ->
page =
Actors.build_actors_by_username_or_name_page(
Actors.search_actors(
term,
[
actor_type: [result_type],
actor_type: result_type,
radius: Map.get(args, :radius),
location: Map.get(args, :location),
minimum_visibility: Map.get(args, :minimum_visibility, :public)
minimum_visibility: Map.get(args, :minimum_visibility, :public),
current_actor_id: Map.get(args, :current_actor_id),
exclude_my_groups: Map.get(args, :exclude_my_groups, false)
],
page,
limit

View File

@@ -13,7 +13,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Followers do
@spec find_followers_for_group(Actor.t(), map(), map()) :: {:ok, Page.t()}
def find_followers_for_group(
%Actor{id: group_id} = group,
%{page: page, limit: limit} = args,
args,
%{
context: %{
current_user: %User{role: user_role},
@@ -21,15 +21,23 @@ defmodule Mobilizon.GraphQL.Resolvers.Followers do
}
}
) do
followers = group_followers(group, args)
if Actors.is_moderator?(actor_id, group_id) or is_moderator(user_role) do
{:ok,
Actors.list_paginated_followers_for_actor(group, Map.get(args, :approved), page, limit)}
{:ok, followers}
else
{:error, :unauthorized}
{:ok, %Page{followers | elements: []}}
end
end
def find_followers_for_group(_, _, _), do: {:error, :unauthenticated}
def find_followers_for_group(%Actor{} = group, args, _) do
followers = group_followers(group, args)
{:ok, %Page{followers | elements: []}}
end
defp group_followers(group, %{page: page, limit: limit} = args) do
Actors.list_paginated_followers_for_actor(group, Map.get(args, :approved), page, limit)
end
@spec update_follower(any(), map(), map()) :: {:ok, Follower.t()} | {:error, any()}
def update_follower(_, %{id: follower_id, approved: approved}, %{

View File

@@ -21,7 +21,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Search do
"""
@spec search_groups(any(), map(), Absinthe.Resolution.t()) ::
{:ok, Page.t(Actor.t())} | {:error, String.t()}
def search_groups(_parent, %{page: page, limit: limit} = args, _resolution) do
def search_groups(
_parent,
%{page: page, limit: limit} = args,
%{context: context} = _resolution
) do
current_actor = Map.get(context, :current_actor, nil)
current_actor_id = if current_actor, do: current_actor.id, else: nil
args = Map.put(args, :current_actor_id, current_actor_id)
Search.search_actors(args, page, limit, :Group)
end

View File

@@ -59,6 +59,14 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
arg(:term, :string, default_value: "", description: "Search term")
arg(:location, :string, description: "A geohash for coordinates")
arg(:exclude_my_groups, :boolean,
description: "Whether to include the groups the current actor is member or follower"
)
arg(:minimum_visibility, :group_visibility,
description: "The minimum visibility the group must have"
)
arg(:radius, :float,
default_value: 50,
description: "Radius around the location to search in"