fix(backend): fix sending N notifications to a single conversation participant
Because of the conversation participant ID being necessary in the email, we launch N jobs to send notifications, so we need to send the email straight away. Anonymous participants are always only a single conversation actor participant, so we're fine Closes #1384 Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
681f8dcd04
commit
95379885c8
|
@ -792,7 +792,7 @@ defmodule Mobilizon.Events do
|
|||
end
|
||||
end
|
||||
|
||||
def get_participant(event_id, actor_id, %{}) do
|
||||
def get_participant(event_id, actor_id, _params) do
|
||||
case Participant
|
||||
|> Repo.get_by(event_id: event_id, actor_id: actor_id)
|
||||
|> Repo.preload(@participant_preloads) do
|
||||
|
|
|
@ -4,7 +4,7 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
|||
"""
|
||||
|
||||
alias Mobilizon.Activities.Activity
|
||||
alias Mobilizon.{Actors, Events, Users}
|
||||
alias Mobilizon.{Actors, Config, Events, Users}
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Service.Notifier
|
||||
|
@ -37,9 +37,10 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
|||
end
|
||||
|
||||
defp special_handling("conversation_created", args, activity) do
|
||||
notify_participants(
|
||||
notify_participant(
|
||||
get_in(args, ["subject_params", "conversation_event_id"]),
|
||||
activity,
|
||||
get_in(args, ["participant", "actor_id"]),
|
||||
args["author_id"]
|
||||
)
|
||||
end
|
||||
|
@ -143,6 +144,24 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
|||
notify_anonymous_participants(event_id, activity)
|
||||
end
|
||||
|
||||
defp notify_participant(nil, _activity, _conversation_participant_actor_id, _author_id),
|
||||
do: :ok
|
||||
|
||||
defp notify_participant(event_id, activity, conversation_participant_actor_id, author_id) do
|
||||
# Anonymous participation
|
||||
if conversation_participant_actor_id == Config.anonymous_actor_id() do
|
||||
notify_anonymous_participants(event_id, activity)
|
||||
else
|
||||
[conversation_participant_actor_id]
|
||||
|> users_from_actor_ids(author_id)
|
||||
|> Enum.each(fn user ->
|
||||
Notifier.Email.send_anonymous_activity(user.email, activity,
|
||||
locale: Map.get(user, :locale, "en")
|
||||
)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
defp notify_anonymous_participants(nil, _activity), do: :ok
|
||||
|
||||
defp notify_anonymous_participants(event_id, activity) do
|
||||
|
@ -154,7 +173,7 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
|||
|> Enum.map(fn %Participant{metadata: metadata} -> metadata end)
|
||||
|> Enum.map(fn %{email: email} = metadata ->
|
||||
Notifier.Email.send_anonymous_activity(email, activity,
|
||||
locale: Map.get(metadata, :locale, "en")
|
||||
locale: Map.get(metadata, :locale, "en") || "en"
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue