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:
@@ -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