Handle events with no physical location

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-10-03 19:26:35 +02:00
parent 4f1465e84d
commit f0c8fa2525
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 6 additions and 25 deletions

View file

@ -222,26 +222,6 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
{:ok, events}
end
@spec organizer_next_public_event(Event.t()) :: list(Event.t())
defp organizer_next_public_event(%Event{attributed_to: %Actor{} = group, uuid: uuid}) do
[Events.get_upcoming_public_event_for_actor(group, uuid)]
|> Enum.filter(&is_map/1)
end
defp organizer_next_public_event(%Event{organizer_actor: %Actor{} = profile, uuid: uuid}) do
[Events.get_upcoming_public_event_for_actor(profile, uuid)]
|> Enum.filter(&is_map/1)
end
@spec similar_events_common_tags(list(Event.t()), Event.t()) :: list(Event.t())
defp similar_events_common_tags(events, %Event{tags: tags, uuid: uuid}) do
events
|> Enum.concat(Events.list_events_by_tags(tags, @number_of_related_events))
|> Enum.filter(fn event -> event.uuid != uuid end)
# uniq_by : It's possible event_from_same_actor is inside events_from_tags
|> uniq_events()
end
@spec add_latest_events(list(Event.t())) :: list(Event.t())
defp add_latest_events(events) do
if @number_of_related_events - length(events) > 0 do

View file

@ -1691,11 +1691,12 @@ defmodule Mobilizon.Events do
def related_events(%Event{
id: event_id,
tags: tags,
physical_address: %Address{geom: geom},
physical_address: physical_address,
category: category,
language: language
}) do
event_tags_ids = Enum.map(tags, & &1.id)
geom = if is_nil(physical_address), do: nil, else: physical_address.geom
Event
|> distinct([e], e.id)
@ -1704,14 +1705,14 @@ defmodule Mobilizon.Events do
|> where(
[e, et, a],
fragment(
"(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (? is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 > ?",
"(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 > ?",
e.language,
^language,
et.tag_id,
^event_tags_ids,
e.category,
^category,
a.geom,
^geom,
^geom,
a.geom,
5000,
@ -1723,14 +1724,14 @@ defmodule Mobilizon.Events do
|> order_by(
[e, et, a],
fragment(
"(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (? is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 DESC",
"(? = ?)::int * 5 + (? = ALL(?))::int * 2 + (? = ?)::int + (?::geography is null or ST_DWithin(?::geography, ?::geography, ?::float))::int * 2 DESC",
e.language,
^language,
et.tag_id,
^event_tags_ids,
e.category,
^category,
a.geom,
^geom,
^geom,
a.geom,
5000