Refactor User.post_register_action/1 emails

This commit is contained in:
Alex Gleason 2020-10-12 17:21:08 -05:00
parent cb29769a22
commit 66e00ace7c
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

View File

@ -779,21 +779,10 @@ defmodule Pleroma.User do
end end
def post_register_action(%User{approval_pending: true} = user) do def post_register_action(%User{approval_pending: true} = user) do
# Send approval pending email to user with {:ok, _} <- send_user_approval_email(user),
user {:ok, _} <- send_admin_approval_emails(user) do
|> Pleroma.Emails.UserEmail.approval_pending_email() {:ok, user}
|> Pleroma.Emails.Mailer.deliver_async() end
# 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}
end end
def post_register_action(%User{approval_pending: false, confirmation_pending: false} = user) do def post_register_action(%User{approval_pending: false, confirmation_pending: false} = user) do
@ -806,6 +795,26 @@ defmodule Pleroma.User do
end end
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 def send_welcome_message(user) do
if User.WelcomeMessage.enabled?() do if User.WelcomeMessage.enabled?() do
User.WelcomeMessage.post_message(user) User.WelcomeMessage.post_message(user)