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

@@ -26,6 +26,7 @@ defmodule Mobilizon.Web.Email.Event do
Event.t(),
Event.t(),
MapSet.t(),
String.t(),
String.t()
) ::
Bamboo.Email.t()
@@ -36,8 +37,8 @@ defmodule Mobilizon.Web.Email.Event do
%Event{} = old_event,
%Event{} = event,
changes,
timezone \\ "Etc/UTC",
locale \\ "en"
timezone,
locale
) do
Gettext.put_locale(locale)
@@ -70,13 +71,15 @@ defmodule Mobilizon.Web.Email.Event do
%Event{id: event_id} = event,
changes
) do
important = MapSet.new(@important_changes)
important = @important_changes |> Enum.map(&to_string/1) |> MapSet.new()
diff =
changes
|> Map.keys()
|> MapSet.new()
|> MapSet.intersection(important)
|> Enum.map(&String.to_existing_atom/1)
|> MapSet.new()
if MapSet.size(diff) > 0 do
Repo.transaction(fn ->
@@ -178,7 +181,7 @@ defmodule Mobilizon.Web.Email.Event do
locale
) do
email
|> Email.Event.event_updated(participant, actor, old_event, event, diff, timezone, locale)
|> event_updated(participant, actor, old_event, event, diff, timezone, locale)
|> Email.Mailer.send_email_later()
end
end

View File

@@ -1,22 +1,14 @@
<%= gettext "Event update!" %>
==
<%= gettext "There have been changes for %{title} so we'd thought we'd let you know.", title: @old_event.title %>
<%= if MapSet.member?(@changes, :status) do %>
<%= case @event.status do %>
<% :confirmed -> %>
<%= gettext "This event has been confirmed" %>
<% :tentative -> %>
<%= gettext "This event has yet to be confirmed: organizers will let you know if they do confirm it." %>
<% :cancelled -> %>
<%= gettext "This event has been cancelled by its organizers. Sorry!" %>
<% end %>
<% end %>
<%= if MapSet.member?(@changes, :title) do %>
<%= gettext "New title: %{title}", title: @event.title %>
<% end %>
<%= if MapSet.member?(@changes, :begins_on) do %><%= render("date/event_tz_date.text", event: @event, date: @event.begins_on, timezone: @timezone, locale: @locale) %>
<% end %>
<%= if MapSet.member?(@changes, :ends_on) && !is_nil(@event.ends_on) do %><%= render("date/event_tz_date.text", event: @event, date: @event.ends_on, timezone: @timezone, locale: @locale) %>
<% end %>
<%= if MapSet.member?(@changes, :status) do %><%= case @event.status do %><% :confirmed -> %><%= gettext "This event has been confirmed" %><% :tentative -> %>
<%= gettext "This event has yet to be confirmed: organizers will let you know if they do confirm it." %><% :cancelled -> %>
<%= gettext "This event has been cancelled by its organizers. Sorry!" %><% end %><% end %><%= if MapSet.member?(@changes, :title) do %>
<%= gettext "New title: %{title}", title: @event.title %><% end %><%= if MapSet.member?(@changes, :begins_on) do %>
<%= gettext "New start date:" %> <%= render("date/event_tz_date.text", event: @event, date: @event.begins_on, timezone: @timezone, locale: @locale) %><% end %><%= if MapSet.member?(@changes, :ends_on) && !is_nil(@event.ends_on) do %>
<%= gettext "New end date:" %> <%= render("date/event_tz_date.text", event: @event, date: @event.ends_on, timezone: @timezone, locale: @locale) %><% end %><%= if MapSet.member?(@changes, :physical_address) do %>
<%= gettext "New location:" %> <%= Mobilizon.Addresses.Address.representation(@event.physical_address) %><% end %>
<%= gettext "Visit the updated event page: %{link}", link: Routes.page_url(Mobilizon.Web.Endpoint, :event, @event.uuid) %>
<%= ngettext "Would you wish to cancel your attendance, visit the event page through the link above and click the « Attending » button.", "Would you wish to cancel your attendance to one or several events, visit the event pages through the links above and click the « Attending » button.", 1 %>