From 3ed43a3575eb1e20ad13be9f42f2af509956564f Mon Sep 17 00:00:00 2001 From: CMK Date: Mon, 31 May 2021 16:57:48 +0800 Subject: [PATCH] fix: profile field edit update logic issue --- .../Scene/Profile/Header/View/ProfileFieldView.swift | 1 - .../API/Mastodon+API+Account+Credentials.swift | 12 +++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Mastodon/Scene/Profile/Header/View/ProfileFieldView.swift b/Mastodon/Scene/Profile/Header/View/ProfileFieldView.swift index 14e5e4b33..e008e1bce 100644 --- a/Mastodon/Scene/Profile/Header/View/ProfileFieldView.swift +++ b/Mastodon/Scene/Profile/Header/View/ProfileFieldView.swift @@ -30,7 +30,6 @@ final class ProfileFieldView: UIView { textField.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 20) textField.textColor = Asset.Colors.Label.primary.color textField.placeholder = L10n.Scene.Profile.Fields.Placeholder.label - textField.isEnabled = false return textField }() diff --git a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Account+Credentials.swift b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Account+Credentials.swift index cbc4fb8e2..e0980165d 100644 --- a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Account+Credentials.swift +++ b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Account+Credentials.swift @@ -217,9 +217,15 @@ extension Mastodon.API.Account { source.sensitive.flatMap { data.append(Data.multipart(key: "source[privacy]", value: $0)) } source.language.flatMap { data.append(Data.multipart(key: "source[privacy]", value: $0)) } } - for (i, fieldsAttribute) in (fieldsAttributes ?? []).enumerated() { - data.append(Data.multipart(key: "fields_attributes[\(i)][name]", value: fieldsAttribute.name)) - data.append(Data.multipart(key: "fields_attributes[\(i)][value]", value: fieldsAttribute.value)) + if let fieldsAttributes = fieldsAttributes { + if fieldsAttributes.isEmpty { + data.append(Data.multipart(key: "fields_attributes[]", value: "")) + } else { + for (i, fieldsAttribute) in fieldsAttributes.enumerated() { + data.append(Data.multipart(key: "fields_attributes[\(i)][name]", value: fieldsAttribute.name)) + data.append(Data.multipart(key: "fields_attributes[\(i)][value]", value: fieldsAttribute.value)) + } + } } data.append(Data.multipartEnd())