From f67bd900f7636a016e65d93f755595a329284d8b Mon Sep 17 00:00:00 2001 From: Massedil Date: Fri, 22 Nov 2024 18:45:11 +0100 Subject: [PATCH] Issue #1567 : use ends_on for comparaisons to get future and ongoing events --- lib/mobilizon/events/events.ex | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index b3786952f..0b48fb02a 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -530,7 +530,9 @@ defmodule Mobilizon.Events do group_id |> event_for_group_query() |> event_filter_visibility(visibility) - |> event_filter_begins_on(after_datetime, before_datetime) + # We want future and ongoing events, so we use ends_on + # See issue #1567 + |> event_filter_ends_on(after_datetime, before_datetime) |> event_order_by(order_by, order_direction) |> preload_for_event() |> Page.build_page(page, limit) @@ -2024,6 +2026,26 @@ defmodule Mobilizon.Events do |> where([e], e.begins_on > ^after_datetime) end + defp event_filter_ends_on(query, nil, nil), do: query + + defp event_filter_ends_on(query, %DateTime{} = after_datetime, nil) do + where(query, [e], e.ends_on > ^after_datetime) + end + + defp event_filter_ends_on(query, nil, %DateTime{} = before_datetime) do + where(query, [e], e.ends_on < ^before_datetime) + end + + defp event_filter_ends_on( + query, + %DateTime{} = after_datetime, + %DateTime{} = before_datetime + ) do + query + |> where([e], e.ends_on < ^before_datetime) + |> where([e], e.ends_on > ^after_datetime) + end + defp event_order_by(query, order_by, direction) when order_by in [:begins_on, :inserted_at, :updated_at] and direction in [:asc, :desc] do order_by_instruction = Keyword.new([{direction, order_by}])