feat: allow to filter events by local-only
In addition to internal (self + federated) and global (global external search engine), introduce the self possibility Closes #1322 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -56,7 +56,8 @@ defmodule Mobilizon.GraphQL.API.Search do
|
||||
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),
|
||||
exclude_stale_actors: true
|
||||
exclude_stale_actors: true,
|
||||
local_only: Map.get(args, :search_target, :internal) == :self
|
||||
],
|
||||
page,
|
||||
limit
|
||||
@@ -94,7 +95,13 @@ defmodule Mobilizon.GraphQL.API.Search do
|
||||
|
||||
{:ok, service.search_events(Keyword.new(args, fn {k, v} -> {k, v} end))}
|
||||
else
|
||||
{:ok, Events.build_events_for_search(Map.put(args, :term, term), page, limit)}
|
||||
results =
|
||||
args
|
||||
|> Map.put(:term, term)
|
||||
|> Map.put(:local_only, Map.get(args, :search_target, :internal) == :self)
|
||||
|> Events.build_events_for_search(page, limit)
|
||||
|
||||
{:ok, results}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -160,6 +160,8 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
|
||||
end
|
||||
|
||||
enum :search_target do
|
||||
value(:self, description: "Search only on content from this instance")
|
||||
|
||||
value(:internal,
|
||||
description: "Search on content from this instance and from the followed instances"
|
||||
)
|
||||
|
||||
@@ -525,6 +525,7 @@ defmodule Mobilizon.Actors do
|
||||
Keyword.get(options, :radius),
|
||||
Keyword.get(options, :bbox)
|
||||
)
|
||||
|> filter_by_local_only(Keyword.get(options, :local_only, false))
|
||||
|> actors_for_location(Keyword.get(options, :location), Keyword.get(options, :radius))
|
||||
|> events_for_bounding_box(Keyword.get(options, :bbox))
|
||||
|> filter_by_type(Keyword.get(options, :actor_type, :Group))
|
||||
@@ -1418,6 +1419,13 @@ defmodule Mobilizon.Actors do
|
||||
|
||||
defp maybe_join_address(query, _location, _radius, _bbox), do: query
|
||||
|
||||
@spec filter_by_local_only(Ecto.Queryable.t(), boolean()) :: Ecto.Query.t()
|
||||
defp filter_by_local_only(query, true) do
|
||||
where(query, [q], is_nil(q.domain))
|
||||
end
|
||||
|
||||
defp filter_by_local_only(query, false), do: query
|
||||
|
||||
@spec actors_for_location(Ecto.Queryable.t(), String.t(), integer()) :: Ecto.Query.t()
|
||||
defp actors_for_location(query, location, radius)
|
||||
when is_valid_string(location) and not is_nil(radius) do
|
||||
|
||||
@@ -581,6 +581,7 @@ defmodule Mobilizon.Events do
|
||||
|> events_for_bounding_box(args)
|
||||
|> filter_online(args)
|
||||
|> filter_draft()
|
||||
|> filter_local(if Map.get(args, :local_only, nil) == true, do: true, else: nil)
|
||||
|> filter_local_or_from_followed_instances_events()
|
||||
|> filter_public_visibility()
|
||||
|> event_order(Map.get(args, :sort_by, :match_desc), search_string)
|
||||
|
||||
Reference in New Issue
Block a user