Extract if block into private function
authorkPherox <admin@mail.kr-kp.com>
Mon, 26 Aug 2019 08:09:32 +0000 (17:09 +0900)
committerAriadne Conill <ariadne@dereferenced.org>
Sun, 6 Oct 2019 15:14:53 +0000 (15:14 +0000)
lib/pleroma/web/mastodon_api/controllers/mastodon_api_controller.ex

index f20105bee97af7b7ea0045b7ec370e52714b5a43..fcca6858d640cde3c87c6009952228626c684541 100644 (file)
@@ -119,6 +119,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
     end
   end
 
+  defp normalize_fields_attributes(fields) do
+    if Enum.all?(fields, &is_tuple/1) do
+      Enum.map(fields, fn {_, v} -> v end)
+    else
+      fields
+    end
+  end
+
   def update_credentials(%{assigns: %{user: user}} = conn, params) do
     original_user = user
 
@@ -146,11 +154,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
     params =
       if Map.has_key?(params, "fields_attributes") do
         Map.update!(params, "fields_attributes", fn fields ->
-          if Enum.all?(fields, &is_tuple/1) do
-            Enum.map(fields, fn {_, v} -> v end)
-          else
-            fields
-          end
+          fields
+          |> normalize_fields_attributes()
           |> Enum.filter(fn %{"name" => n} -> n != "" end)
         end)
       else