Add json_ld info to more emails

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-10-18 11:09:02 +02:00
parent f9ddeb80fb
commit f31454c692
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -10,6 +10,7 @@ defmodule Mobilizon.Web.Email.Notification do
alias Mobilizon.Events.{Event, Participant}
alias Mobilizon.Users.{Setting, User}
alias Mobilizon.Web.Email
alias Mobilizon.Web.JsonLD.ObjectView
@spec before_event_notification(String.t(), Participant.t(), String.t()) ::
Bamboo.Email.t()
@ -30,6 +31,7 @@ defmodule Mobilizon.Web.Email.Notification do
|> assign(:locale, locale)
|> assign(:participant, participant)
|> assign(:subject, subject)
|> assign(:jsonLDMetadata, build_json_ld(participant))
|> Email.add_event_attachment(event)
|> render(:before_event_notification)
end
@ -57,6 +59,7 @@ defmodule Mobilizon.Web.Email.Notification do
|> assign(:total, total)
|> assign(:timezone, timezone)
|> assign(:subject, subject)
|> assign(:jsonLDMetadata, build_json_ld(participations))
|> render(:on_day_notification)
end
@ -83,6 +86,7 @@ defmodule Mobilizon.Web.Email.Notification do
|> assign(:total, total)
|> assign(:timezone, timezone)
|> assign(:subject, subject)
|> assign(:jsonLDMetadata, build_json_ld(participations))
|> render(:notification_each_week)
end
@ -110,4 +114,17 @@ defmodule Mobilizon.Web.Email.Notification do
|> assign(:subject, subject)
|> render(:pending_participation_notification)
end
@spec build_json_ld(Participant.t()) :: String.t()
defp build_json_ld(%Participant{} = participant) do
"participation.json"
|> ObjectView.render(%{participant: participant})
|> Jason.encode!()
end
defp build_json_ld(participations) when is_list(participations) do
participations
|> Enum.map(&ObjectView.render("participation.json", %{participant: &1}))
|> Jason.encode!()
end
end