Attach event ics files to event-related emails
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -6,7 +6,9 @@ defmodule Mobilizon.Web.Email do
|
||||
use Bamboo.Phoenix, view: Mobilizon.Web.EmailView
|
||||
|
||||
alias Ecto.UUID
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.{Config, Events}
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Service.Export.ICalendar
|
||||
alias Mobilizon.Web.EmailView
|
||||
|
||||
@spec base_email(keyword()) :: Bamboo.Email.t()
|
||||
@@ -40,4 +42,18 @@ defmodule Mobilizon.Web.Email do
|
||||
Timex.format!(DateTime.utc_now(), "{WDshort}, {D} {Mshort} {YYYY} {h24}:{m}:{s} {Z}")
|
||||
end
|
||||
end
|
||||
|
||||
def add_event_attachment(%Bamboo.Email{} = email, %Event{id: event_id}) do
|
||||
with {:ok, %Event{} = event} <- Events.get_event_with_preload(event_id),
|
||||
{:ok, event_ics_data} <- ICalendar.export_event(event) do
|
||||
put_attachment(email, %Bamboo.Attachment{
|
||||
filename: Slugger.slugify_downcase(event.title),
|
||||
content_type: "text/calendar",
|
||||
data: event_ics_data
|
||||
})
|
||||
else
|
||||
_ ->
|
||||
email
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,6 +46,7 @@ defmodule Mobilizon.Web.Email.Event do
|
||||
|> assign(:changes, changes)
|
||||
|> assign(:subject, subject)
|
||||
|> assign(:timezone, timezone)
|
||||
|> Email.add_event_attachment(event)
|
||||
|> render(:event_updated)
|
||||
end
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ defmodule Mobilizon.Web.Email.Notification do
|
||||
|> assign(:locale, locale)
|
||||
|> assign(:participant, participant)
|
||||
|> assign(:subject, subject)
|
||||
|> Email.add_event_attachment(event)
|
||||
|> render(:before_event_notification)
|
||||
end
|
||||
|
||||
|
||||
@@ -118,6 +118,7 @@ defmodule Mobilizon.Web.Email.Participation do
|
||||
|> assign(:locale, locale)
|
||||
|> assign(:event, event)
|
||||
|> assign(:subject, subject)
|
||||
|> Email.add_event_attachment(event)
|
||||
|> render(:event_participation_approved)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user