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>
This commit is contained in:
Thomas Citharel
2021-11-10 20:31:29 +01:00
parent 8250d34597
commit 38a3ffc19f
9 changed files with 254 additions and 43 deletions

View File

@@ -0,0 +1,18 @@
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