Fix group notification of new event being sent multiple times
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
1eb111f52f
commit
46236dbe1d
|
@ -17,25 +17,27 @@ defmodule Mobilizon.Web.Email.Group do
|
||||||
# TODO: When we have events restricted to members, don't send emails to followers
|
# TODO: When we have events restricted to members, don't send emails to followers
|
||||||
group
|
group
|
||||||
|> Actors.list_actors_to_notify_from_group_event()
|
|> Actors.list_actors_to_notify_from_group_event()
|
||||||
|
|> Enum.reduce([], fn actor, users ->
|
||||||
|
# No emails for remote actors
|
||||||
|
if is_nil(actor.user_id) do
|
||||||
|
users
|
||||||
|
else
|
||||||
|
users ++ [Users.get_user_with_activity_settings!(actor.user_id)]
|
||||||
|
end
|
||||||
|
end)
|
||||||
|> Enum.each(¬ify_follower(event, group, &1))
|
|> Enum.each(¬ify_follower(event, group, &1))
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_of_new_event(%Event{}), do: :ok
|
def notify_of_new_event(%Event{}), do: :ok
|
||||||
|
|
||||||
defp notify_follower(%Event{} = _event, %Actor{}, %Actor{user_id: nil}), do: :ok
|
defp notify_follower(%Event{} = event, %Actor{type: :Group} = group, %User{
|
||||||
|
|
||||||
defp notify_follower(%Event{} = event, %Actor{type: :Group} = group, %Actor{
|
|
||||||
id: profile_id,
|
|
||||||
user_id: user_id
|
|
||||||
}) do
|
|
||||||
%User{
|
|
||||||
email: email,
|
email: email,
|
||||||
locale: locale,
|
locale: locale,
|
||||||
settings: %Setting{timezone: timezone},
|
settings: %Setting{timezone: timezone},
|
||||||
activity_settings: activity_settings
|
activity_settings: activity_settings,
|
||||||
} = Users.get_user_with_activity_settings!(user_id)
|
default_actor_id: default_actor_id
|
||||||
|
}) do
|
||||||
if profile_id != event.organizer_actor_id &&
|
if default_actor_id != event.organizer_actor_id &&
|
||||||
accepts_new_events_notifications(activity_settings) do
|
accepts_new_events_notifications(activity_settings) do
|
||||||
Gettext.put_locale(locale)
|
Gettext.put_locale(locale)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue