Introduce group basic federation, event new page and notifications
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -19,7 +19,7 @@ defmodule Mobilizon.Web.Email.Event do
|
||||
|
||||
@important_changes [:title, :begins_on, :ends_on, :status]
|
||||
|
||||
@spec event_updated(User.t(), Actor.t(), Event.t(), Event.t(), list(), String.t()) ::
|
||||
@spec event_updated(User.t(), Actor.t(), Event.t(), Event.t(), MapSet.t(), String.t()) ::
|
||||
Bamboo.Email.t()
|
||||
def event_updated(
|
||||
%User{} = user,
|
||||
@@ -82,4 +82,12 @@ defmodule Mobilizon.Web.Email.Event do
|
||||
|> Email.Event.event_updated(actor, old_event, event, diff, locale)
|
||||
|> Email.Mailer.deliver_later()
|
||||
end
|
||||
|
||||
defp send_notification_for_event_update_to_participant(user, old_event, new_event, diff) do
|
||||
require Logger
|
||||
Logger.error(inspect(user))
|
||||
Logger.error(inspect(old_event))
|
||||
Logger.error(inspect(new_event))
|
||||
Logger.error(inspect(diff))
|
||||
end
|
||||
end
|
||||
|
||||
47
lib/web/email/group.ex
Normal file
47
lib/web/email/group.ex
Normal file
@@ -0,0 +1,47 @@
|
||||
defmodule Mobilizon.Web.Email.Group do
|
||||
@moduledoc """
|
||||
Handles emails sent about participation.
|
||||
"""
|
||||
use Bamboo.Phoenix, view: Mobilizon.Web.EmailView
|
||||
|
||||
import Bamboo.Phoenix
|
||||
import Mobilizon.Web.Gettext
|
||||
|
||||
alias Mobilizon.{Actors, Users}
|
||||
alias Mobilizon.Actors.{Actor, Member}
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Web.{Email, Gettext}
|
||||
|
||||
@doc """
|
||||
Send emails to local user
|
||||
"""
|
||||
def send_invite_to_user(
|
||||
%Member{actor: %Actor{user_id: user_id}, parent: %Actor{} = group, role: :invited} =
|
||||
member,
|
||||
locale \\ "en"
|
||||
) do
|
||||
with %User{email: email} <- Users.get_user!(user_id) do
|
||||
Gettext.put_locale(locale)
|
||||
%Actor{name: invited_by_name} = inviter = Actors.get_actor(member.invited_by_id)
|
||||
|
||||
subject =
|
||||
gettext(
|
||||
"You have been invited by %{inviter} to join group %{group}",
|
||||
inviter: invited_by_name,
|
||||
group: group.name
|
||||
)
|
||||
|
||||
Email.base_email(to: email, subject: subject)
|
||||
|> assign(:locale, locale)
|
||||
|> assign(:inviter, inviter)
|
||||
|> assign(:group, group)
|
||||
|> assign(:subject, subject)
|
||||
|> render(:group_invite)
|
||||
|> Email.Mailer.deliver_later()
|
||||
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
||||
# TODO : def send_confirmation_to_inviter()
|
||||
end
|
||||
59
lib/web/email/notification.ex
Normal file
59
lib/web/email/notification.ex
Normal file
@@ -0,0 +1,59 @@
|
||||
defmodule Mobilizon.Web.Email.Notification do
|
||||
@moduledoc """
|
||||
Handles emails sent about event notifications.
|
||||
"""
|
||||
use Bamboo.Phoenix, view: Mobilizon.Web.EmailView
|
||||
|
||||
import Bamboo.Phoenix
|
||||
import Mobilizon.Web.Gettext
|
||||
|
||||
alias Mobilizon.Events.Participant
|
||||
alias Mobilizon.Users.{Setting, User}
|
||||
alias Mobilizon.Web.{Email, Gettext}
|
||||
|
||||
@spec before_event_notification(String.t(), Participant.t(), String.t()) ::
|
||||
Bamboo.Email.t()
|
||||
def before_event_notification(
|
||||
email,
|
||||
%Participant{event: event, role: :participant} = participant,
|
||||
locale \\ "en"
|
||||
) do
|
||||
Gettext.put_locale(locale)
|
||||
|
||||
subject =
|
||||
gettext(
|
||||
"Don't forget to go to %{title}",
|
||||
title: event.title
|
||||
)
|
||||
|
||||
Email.base_email(to: email, subject: subject)
|
||||
|> assign(:locale, locale)
|
||||
|> assign(:participant, participant)
|
||||
|> assign(:subject, subject)
|
||||
|> render(:before_event_notification)
|
||||
end
|
||||
|
||||
def on_day_notification(
|
||||
%User{email: email, settings: %Setting{timezone: timezone}},
|
||||
participations,
|
||||
total,
|
||||
locale \\ "en"
|
||||
) do
|
||||
Gettext.put_locale(locale)
|
||||
participation = hd(participations)
|
||||
|
||||
subject =
|
||||
ngettext("One event planned today", "%{nb_events} events planned today", total,
|
||||
nb_events: total
|
||||
)
|
||||
|
||||
Email.base_email(to: email, subject: subject)
|
||||
|> assign(:locale, locale)
|
||||
|> assign(:participation, participation)
|
||||
|> assign(:participations, participations)
|
||||
|> assign(:total, total)
|
||||
|> assign(:timezone, timezone)
|
||||
|> assign(:subject, subject)
|
||||
|> render(:on_day_notification)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user