From 66e00ace7c0708f2f9361bc6e1008ccea08cb6ef Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 12 Oct 2020 17:21:08 -0500 Subject: [PATCH] Refactor User.post_register_action/1 emails --- lib/pleroma/user.ex | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index c6767cfca..0978cc02c 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -779,21 +779,10 @@ def post_register_action(%User{confirmation_pending: true} = user) do end def post_register_action(%User{approval_pending: true} = user) do - # Send approval pending email to user - user - |> Pleroma.Emails.UserEmail.approval_pending_email() - |> Pleroma.Emails.Mailer.deliver_async() - - # Notify admins - all_superusers() - |> Enum.filter(fn user -> not is_nil(user.email) end) - |> Enum.each(fn superuser -> - superuser - |> Pleroma.Emails.AdminEmail.new_unapproved_registration(user) - |> Pleroma.Emails.Mailer.deliver_async() - end) - - {:ok, user} + with {:ok, _} <- send_user_approval_email(user), + {:ok, _} <- send_admin_approval_emails(user) do + {:ok, user} + end end def post_register_action(%User{approval_pending: false, confirmation_pending: false} = user) do @@ -806,6 +795,26 @@ def post_register_action(%User{approval_pending: false, confirmation_pending: fa end end + defp send_user_approval_email(user) do + user + |> Pleroma.Emails.UserEmail.approval_pending_email() + |> Pleroma.Emails.Mailer.deliver_async() + + {:ok, :enqueued} + end + + defp send_admin_approval_emails(user) do + all_superusers() + |> Enum.filter(fn user -> not is_nil(user.email) end) + |> Enum.each(fn superuser -> + superuser + |> Pleroma.Emails.AdminEmail.new_unapproved_registration(user) + |> Pleroma.Emails.Mailer.deliver_async() + end) + + {:ok, :enqueued} + end + def send_welcome_message(user) do if User.WelcomeMessage.enabled?() do User.WelcomeMessage.post_message(user)