@@ -10,6 +10,7 @@ defmodule Mobilizon.Web.Email.Activity do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Config
|
||||
alias Mobilizon.Web.Email
|
||||
require Logger
|
||||
|
||||
@spec direct_activity(String.t(), list(), Keyword.t()) :: Swoosh.Email.t()
|
||||
def direct_activity(
|
||||
@@ -39,6 +40,36 @@ defmodule Mobilizon.Web.Email.Activity do
|
||||
end
|
||||
|
||||
@spec anonymous_activity(String.t(), Activity.t(), Keyword.t()) :: Swoosh.Email.t()
|
||||
def anonymous_activity(
|
||||
email,
|
||||
%Activity{subject_params: subject_params, type: :conversation} = activity,
|
||||
options
|
||||
) do
|
||||
locale = Keyword.get(options, :locale, "en")
|
||||
|
||||
subject =
|
||||
dgettext(
|
||||
"activity",
|
||||
"Informations about your event %{event}",
|
||||
event: subject_params["conversation_event_title"]
|
||||
)
|
||||
|
||||
conversation = Mobilizon.Conversations.get_conversation(activity.object_id)
|
||||
|
||||
Logger.debug("Going to send anonymous activity of type #{activity.type} to #{email}")
|
||||
|
||||
[to: email, subject: subject]
|
||||
|> Email.base_email()
|
||||
|> render_body(:email_anonymous_activity, %{
|
||||
subject: subject,
|
||||
activity: activity,
|
||||
locale: locale,
|
||||
extra: %{
|
||||
"conversation" => conversation
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
def anonymous_activity(email, %Activity{subject_params: subject_params} = activity, options) do
|
||||
locale = Keyword.get(options, :locale, "en")
|
||||
|
||||
@@ -49,6 +80,8 @@ defmodule Mobilizon.Web.Email.Activity do
|
||||
event: subject_params["event_title"]
|
||||
)
|
||||
|
||||
Logger.debug("Going to send anonymous activity of type #{activity.type} to #{email}")
|
||||
|
||||
[to: email, subject: subject]
|
||||
|> Email.base_email()
|
||||
|> render_body(:email_anonymous_activity, %{
|
||||
|
||||
@@ -35,61 +35,164 @@
|
||||
<tr>
|
||||
<td align="center" valign="top" width="600">
|
||||
<![endif]-->
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
|
||||
<!-- COPY -->
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td
|
||||
align="center"
|
||||
style="border-radius: 3px; text-align: left; padding: 10px 5% 0px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400;line-height: 25px;"
|
||||
>
|
||||
<%= dgettext(
|
||||
"activity",
|
||||
"%{profile} has posted an announcement under event %{event}.",
|
||||
%{
|
||||
profile: "<b>#{escape_html(display_name_and_username(@activity.author))}</b>",
|
||||
event:
|
||||
"<a href=\"#{Routes.page_url(Mobilizon.Web.Endpoint,
|
||||
:event,
|
||||
@activity.subject_params["event_uuid"]) |> URI.decode()}\">
|
||||
<%= case @activity.type do %>
|
||||
<% :comment -> %>
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
|
||||
<!-- COPY -->
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td
|
||||
align="center"
|
||||
style="border-radius: 3px; text-align: left; padding: 10px 5% 0px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400;line-height: 25px;"
|
||||
>
|
||||
<%= dgettext(
|
||||
"activity",
|
||||
"%{profile} has posted a public announcement under event %{event}.",
|
||||
%{
|
||||
profile:
|
||||
"<b>#{escape_html(display_name_and_username(@activity.author))}</b>",
|
||||
event:
|
||||
"<a href=\"#{Routes.page_url(Mobilizon.Web.Endpoint,
|
||||
:event,
|
||||
@activity.subject_params["event_uuid"]) |> URI.decode()}\">
|
||||
#{escape_html(@activity.subject_params["event_title"])}
|
||||
</a>"
|
||||
}
|
||||
)
|
||||
|> raw %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="center" style="padding: 20px 30px 60px 30px;">
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td align="center" style="border-radius: 3px;" bgcolor="#3C376E">
|
||||
<a
|
||||
href={
|
||||
}
|
||||
)
|
||||
|> raw %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="center" style="padding: 20px 30px 60px 30px;">
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td align="center" style="border-radius: 3px;" bgcolor="#3C376E">
|
||||
<a
|
||||
href={
|
||||
"#{Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"])}"
|
||||
}
|
||||
target="_blank"
|
||||
style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;"
|
||||
>
|
||||
<%= gettext("Visit event page") %>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
target="_blank"
|
||||
style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;"
|
||||
>
|
||||
<%= gettext("Visit event page") %>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<% :conversation -> %>
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;">
|
||||
<!-- COPY -->
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td
|
||||
align="center"
|
||||
style="border-radius: 3px; text-align: left; padding: 10px 5% 0px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400;line-height: 25px;"
|
||||
>
|
||||
<%= dgettext(
|
||||
"activity",
|
||||
"%{profile} has posted a private announcement about event %{event}.",
|
||||
%{
|
||||
profile:
|
||||
"<b>#{escape_html(display_name_and_username(@activity.author))}</b>",
|
||||
event:
|
||||
"<a href=\"#{Routes.page_url(Mobilizon.Web.Endpoint,
|
||||
:event,
|
||||
@activity.subject_params["conversation_event_uuid"]) |> URI.decode()}\">
|
||||
#{escape_html(@activity.subject_params["conversation_event_title"])}
|
||||
</a>"
|
||||
}
|
||||
)
|
||||
|> raw %>
|
||||
<%= dgettext(
|
||||
"activity",
|
||||
"It might give details on how to join the event, so make sure to read it appropriately."
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="center" style="padding: 20px 30px 60px 30px;">
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<blockquote style="border-left-width: 0.25rem;border-left-color: #e2e8f0;border-left-style: solid;padding-left: 1em;margin: 0;text-align: start;color: #474467;font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400;line-height: 25px;">
|
||||
<%= @extra["conversation"].last_comment.text
|
||||
|> sanitize_to_basic_html()
|
||||
|> raw() %>
|
||||
</blockquote>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td
|
||||
align="center"
|
||||
style="border-radius: 3px; text-align: left; padding: 10px 5% 0px 30px; color: #474467; font-family: 'Roboto', Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400;line-height: 25px;"
|
||||
>
|
||||
<%= dgettext(
|
||||
"activity",
|
||||
"This information is sent privately to you as a person who registered for this event. Share the informations above with other people with caution."
|
||||
) %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="left">
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td bgcolor="#ffffff" align="center" style="padding: 20px 30px 60px 30px;">
|
||||
<table border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td align="center" style="border-radius: 3px;" bgcolor="#3C376E">
|
||||
<a
|
||||
href={
|
||||
"#{Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["conversation_event_uuid"])}"
|
||||
}
|
||||
target="_blank"
|
||||
style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #3C376E; display: inline-block;"
|
||||
>
|
||||
<%= gettext("Visit event page") %>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<% end %>
|
||||
<!--[if (gte mso 9)|(IE)]>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,11 +1,30 @@
|
||||
<%= @subject %>
|
||||
|
||||
==
|
||||
|
||||
<%= dgettext("activity", "%{profile} has posted an announcement under event %{event}.",
|
||||
<%= case @activity.type do %>
|
||||
<% :comment -> %>
|
||||
<%= dgettext("activity", "%{profile} has posted a public announcement under event %{event}.",
|
||||
%{
|
||||
profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author),
|
||||
event: @activity.subject_params["event_title"]
|
||||
}
|
||||
) %>
|
||||
<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode() %>
|
||||
<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["event_uuid"]) |> URI.decode() %>
|
||||
<% :conversation -> %>
|
||||
<%= dgettext("activity", "%{profile} has posted a private announcement about event %{event}.",
|
||||
%{
|
||||
profile: Mobilizon.Actors.Actor.display_name_and_username(@activity.author),
|
||||
event: @activity.subject_params["conversation_event_title"]
|
||||
}
|
||||
) %>
|
||||
<%= dgettext("activity", "It might give details on how to join the event, so make sure to read it appropriately.") %>
|
||||
|
||||
--
|
||||
|
||||
<%= @extra["conversation"].last_comment.text |> html_to_text() |> mail_quote() %>
|
||||
|
||||
--
|
||||
|
||||
<%= dgettext("activity", "This information is sent privately to you as a person who registered for this event. Share the informations above with other people with caution.") %>
|
||||
<%= Routes.page_url(Mobilizon.Web.Endpoint, :event, @activity.subject_params["conversation_event_uuid"]) |> URI.decode() %>
|
||||
<% end %>
|
||||
@@ -7,6 +7,7 @@ defmodule Mobilizon.Web.EmailView do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.Address
|
||||
alias Mobilizon.Service.DateTime, as: DateTimeRenderer
|
||||
alias Mobilizon.Service.Formatter.{HTML, Text}
|
||||
alias Mobilizon.Web.Router.Helpers, as: Routes
|
||||
import Mobilizon.Web.Gettext
|
||||
import Mobilizon.Service.Metadata.Utils, only: [process_description: 1]
|
||||
@@ -35,6 +36,21 @@ defmodule Mobilizon.Web.EmailView do
|
||||
|> safe_to_string()
|
||||
end
|
||||
|
||||
@spec sanitize_to_basic_html(String.t()) :: String.t()
|
||||
def sanitize_to_basic_html(html) do
|
||||
case HTML.basic_html(html) do
|
||||
{:ok, html} -> html
|
||||
_ -> ""
|
||||
end
|
||||
end
|
||||
|
||||
defdelegate html_to_text(html), to: HTML
|
||||
|
||||
def mail_quote(text) do
|
||||
# https://www.emailonacid.com/blog/article/email-development/line-length-in-html-email/
|
||||
Text.quote_paragraph(text, 78)
|
||||
end
|
||||
|
||||
def escaped_display_name_and_username(actor) do
|
||||
actor
|
||||
|> display_name_and_username()
|
||||
|
||||
Reference in New Issue
Block a user