Refactor User.post_register_action/1 emails
authorAlex Gleason <alex@alexgleason.me>
Mon, 12 Oct 2020 22:21:08 +0000 (17:21 -0500)
committerAlex Gleason <alex@alexgleason.me>
Mon, 12 Oct 2020 22:21:08 +0000 (17:21 -0500)
lib/pleroma/user.ex

index c6767cfca19ed4c667f8fb961d8a515da0568adc..0978cc02c500711c5a416e60549939d2819246e0 100644 (file)
@@ -779,12 +779,31 @@ defmodule Pleroma.User do
   end
 
   def post_register_action(%User{approval_pending: true} = user) do
-    # Send approval pending email to 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
+    with {:ok, user} <- autofollow_users(user),
+         {:ok, user} <- set_cache(user),
+         {:ok, _} <- send_welcome_email(user),
+         {:ok, _} <- send_welcome_message(user),
+         {:ok, _} <- send_welcome_chat_message(user) do
+      {:ok, user}
+    end
+  end
+
+  defp send_user_approval_email(user) do
     user
     |> Pleroma.Emails.UserEmail.approval_pending_email()
     |> Pleroma.Emails.Mailer.deliver_async()
 
-    # Notify admins
+    {: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 ->
@@ -793,17 +812,7 @@ defmodule Pleroma.User do
       |> Pleroma.Emails.Mailer.deliver_async()
     end)
 
-    {:ok, user}
-  end
-
-  def post_register_action(%User{approval_pending: false, confirmation_pending: false} = user) do
-    with {:ok, user} <- autofollow_users(user),
-         {:ok, user} <- set_cache(user),
-         {:ok, _} <- send_welcome_email(user),
-         {:ok, _} <- send_welcome_message(user),
-         {:ok, _} <- send_welcome_chat_message(user) do
-      {:ok, user}
-    end
+    {:ok, :enqueued}
   end
 
   def send_welcome_message(user) do