diff options
author | kPherox <admin@mail.kr-kp.com> | 2019-08-26 17:09:32 +0900 |
---|---|---|
committer | kPherox <admin@mail.kr-kp.com> | 2019-08-26 17:09:32 +0900 |
commit | 8ca4f145a51e92c9f3a6c374ceddfac22ea300d9 (patch) | |
tree | 125b91fb8744fe4040b49c3aac77f14f80d22640 | |
parent | eb75ea502d9c608ef892feeda02fa49578e9c369 (diff) | |
download | pleroma-8ca4f145a51e92c9f3a6c374ceddfac22ea300d9.tar.gz |
Extract if block into private function
-rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index ca2230630..3ca1630f4 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -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 |