@@ -8,6 +8,7 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Service.Notifier
|
||||
require Logger
|
||||
|
||||
use Mobilizon.Service.Workers.Helper, queue: "activity"
|
||||
|
||||
@@ -15,6 +16,7 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
||||
def perform(%Job{args: args}) do
|
||||
{"legacy_notify", args} = Map.pop(args, "op")
|
||||
activity = build_activity(args)
|
||||
Logger.debug("Handling activity #{activity.subject} to notify in LegacyNotifierBuilder")
|
||||
|
||||
if args["subject"] == "participation_event_comment" do
|
||||
notify_anonymous_participants(get_in(args, ["subject_params", "event_id"]), activity)
|
||||
@@ -22,7 +24,7 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
||||
|
||||
args
|
||||
|> users_to_notify(author_id: args["author_id"], group_id: Map.get(args, "group_id"))
|
||||
|> Enum.each(&Notifier.notify(&1, activity, single_activity: true))
|
||||
|> Enum.each(¬ify_user(&1, activity))
|
||||
end
|
||||
|
||||
defp build_activity(args) do
|
||||
@@ -48,6 +50,15 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
||||
users_from_actor_ids(mentionned_actor_ids, Keyword.fetch!(options, :author_id))
|
||||
end
|
||||
|
||||
@spec users_to_notify(map(), Keyword.t()) :: list(Users.t())
|
||||
defp users_to_notify(
|
||||
%{"subject" => subject, "participant" => %{"actor_id" => actor_id}},
|
||||
options
|
||||
)
|
||||
when subject in ["conversation_created", "conversation_replied"] do
|
||||
users_from_actor_ids([actor_id], Keyword.fetch!(options, :author_id))
|
||||
end
|
||||
|
||||
defp users_to_notify(
|
||||
%{"subject" => "discussion_mention", "mentions" => mentionned_actor_ids},
|
||||
options
|
||||
@@ -114,4 +125,9 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
defp notify_user(user, activity) do
|
||||
Logger.debug("Notifying #{user.email} for activity #{activity.subject}")
|
||||
Notifier.notify(user, activity, single_activity: true)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user