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:
18
lib/mobilizon/events/utils.ex
Normal file
18
lib/mobilizon/events/utils.ex
Normal 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
|
||||
Reference in New Issue
Block a user