mobilizon.chapril.org-mobil.../lib/mobilizon/events/utils.ex
Thomas Citharel 38a3ffc19f
Send event creation and event update notifications in a background task
The event update notification is made unique so that repeated changes
only trigger one notificate every 30 minutes

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-11-11 16:29:38 +01:00

19 lines
507 B
Elixir

defmodule Mobilizon.Events.Utils do
@moduledoc """
Utils related to events
"""
@spec calculate_notification_time(DateTime.t()) :: DateTime.t()
def calculate_notification_time(begins_on, options \\ []) do
now = Keyword.get(options, :now, DateTime.utc_now())
notify_at = DateTime.add(now, 1800)
# If the event begins in less than half an hour, send the notification right now
if DateTime.compare(notify_at, begins_on) == :lt do
notify_at
else
now
end
end
end