From 096e42b1c2a5794bd348aba2fd5258e3f906ced6 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Fri, 24 Feb 2023 07:55:24 +0100 Subject: [PATCH] Profile edit: Add metadata editing --- .../Localization/be.lproj/Localizable.strings | 6 ++ .../Localization/ca.lproj/Localizable.strings | 6 ++ .../Localization/de.lproj/Localizable.strings | 6 ++ .../en-GB.lproj/Localizable.strings | 6 ++ .../Localization/en.lproj/Localizable.strings | 6 ++ .../Localization/es.lproj/Localizable.strings | 6 ++ .../Localization/eu.lproj/Localizable.strings | 6 ++ .../Localization/fr.lproj/Localizable.strings | 6 ++ .../Localization/it.lproj/Localizable.strings | 6 ++ .../Localization/ja.lproj/Localizable.strings | 6 ++ .../Localization/ko.lproj/Localizable.strings | 6 ++ .../Localization/nb.lproj/Localizable.strings | 6 ++ .../Localization/nl.lproj/Localizable.strings | 6 ++ .../Localization/pl.lproj/Localizable.strings | 6 ++ .../pt-BR.lproj/Localizable.strings | 6 ++ .../Localization/tr.lproj/Localizable.strings | 6 ++ .../Localization/uk.lproj/Localizable.strings | 6 ++ .../zh-Hans.lproj/Localizable.strings | 6 ++ .../Account/Edit/EditAccountView.swift | 29 +++++++ .../Account/Edit/EditAccountViewModel.swift | 30 ++++++-- Packages/Models/Sources/Models/Account.swift | 3 +- .../Sources/Network/Endpoint/Accounts.swift | 75 ++++++++++++++----- 22 files changed, 218 insertions(+), 27 deletions(-) diff --git a/IceCubesApp/Resources/Localization/be.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/be.lproj/Localizable.strings index 226e0b0a..94d85ffe 100644 --- a/IceCubesApp/Resources/Localization/be.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/be.lproj/Localizable.strings @@ -252,6 +252,12 @@ "account.edit.post-settings.privacy" = "Прыватнасць па змаўчанні"; "account.edit.post-settings.section-title" = "Налады допісу"; "account.edit.post-settings.sensitive" = "Адчувальны змест"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Улюбёны"; "account.follow.follow" = "Сачыць"; "account.follow.following" = "Адсочваю"; diff --git a/IceCubesApp/Resources/Localization/ca.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/ca.lproj/Localizable.strings index 239dd71e..2641fa6c 100644 --- a/IceCubesApp/Resources/Localization/ca.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/ca.lproj/Localizable.strings @@ -246,6 +246,12 @@ "account.edit.post-settings.privacy" = " Privadesa per defecte"; "account.edit.post-settings.section-title" = "Configuració de les publicacions"; "account.edit.post-settings.sensitive" = "Contingut sensible"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Marcat com a favorit per"; "account.follow.follow" = "Segueix"; "account.follow.following" = "Seguint"; diff --git a/IceCubesApp/Resources/Localization/de.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/de.lproj/Localizable.strings index 1950915b..09e3495f 100644 --- a/IceCubesApp/Resources/Localization/de.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/de.lproj/Localizable.strings @@ -247,6 +247,12 @@ "account.edit.post-settings.privacy" = "Standard-Sichtbarkeit"; "account.edit.post-settings.section-title" = "Beitragseinstellungen"; "account.edit.post-settings.sensitive" = "Sensibler Inhalt"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Favorisiert von"; "account.follow.follow" = "Folgen"; "account.follow.following" = "Entfolgen"; diff --git a/IceCubesApp/Resources/Localization/en-GB.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/en-GB.lproj/Localizable.strings index 610d6107..be6a9cca 100644 --- a/IceCubesApp/Resources/Localization/en-GB.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/en-GB.lproj/Localizable.strings @@ -249,6 +249,12 @@ "account.edit.post-settings.privacy" = "Default privacy"; "account.edit.post-settings.section-title" = "Post settings"; "account.edit.post-settings.sensitive" = "Sensitive content"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Favourited by"; "account.follow.follow" = "Follow"; "account.follow.following" = "Following"; diff --git a/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings index 2858f7ed..f71567e4 100644 --- a/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/en.lproj/Localizable.strings @@ -248,6 +248,12 @@ "account.edit.post-settings.privacy" = "Default privacy"; "account.edit.post-settings.section-title" = "Post settings"; "account.edit.post-settings.sensitive" = "Sensitive content"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Favorited by"; "account.follow.follow" = "Follow"; "account.follow.following" = "Following"; diff --git a/IceCubesApp/Resources/Localization/es.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/es.lproj/Localizable.strings index 32798551..73064e34 100644 --- a/IceCubesApp/Resources/Localization/es.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/es.lproj/Localizable.strings @@ -248,6 +248,12 @@ "account.edit.post-settings.privacy" = "Privacidad por defecto"; "account.edit.post-settings.section-title" = "Ajustes de publicaciones"; "account.edit.post-settings.sensitive" = "Contenido sensible"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Marcado como favorito por"; "account.follow.follow" = "Seguir"; "account.follow.following" = "Siguiendo"; diff --git a/IceCubesApp/Resources/Localization/eu.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/eu.lproj/Localizable.strings index 91782a03..5aaf1e63 100644 --- a/IceCubesApp/Resources/Localization/eu.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/eu.lproj/Localizable.strings @@ -247,6 +247,12 @@ "account.edit.post-settings.privacy" = "Defektuzko pribatutasuna"; "account.edit.post-settings.section-title" = "Bidalketen ezarpenak"; "account.edit.post-settings.sensitive" = "Eduki hunkigarria"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Hauek gogoko egin dute:"; "account.follow.follow" = "Jarraitu"; "account.follow.following" = "Jarraitzen"; diff --git a/IceCubesApp/Resources/Localization/fr.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/fr.lproj/Localizable.strings index ed262ac0..75aaeb1e 100644 --- a/IceCubesApp/Resources/Localization/fr.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/fr.lproj/Localizable.strings @@ -247,6 +247,12 @@ "account.edit.post-settings.privacy" = "Confidentialité par défaut"; "account.edit.post-settings.section-title" = "Paramètres des publications"; "account.edit.post-settings.sensitive" = "Contenu sensible"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Favorisé par"; "account.follow.follow" = "Suivre"; "account.follow.following" = "Suivi"; diff --git a/IceCubesApp/Resources/Localization/it.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/it.lproj/Localizable.strings index 8d609a02..cde24d90 100644 --- a/IceCubesApp/Resources/Localization/it.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/it.lproj/Localizable.strings @@ -247,6 +247,12 @@ "account.edit.post-settings.privacy" = "Privacy di default"; "account.edit.post-settings.section-title" = "Impostazioni post"; "account.edit.post-settings.sensitive" = "Contenuto sensibile"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Tra i preferiti di"; "account.follow.follow" = "Segui"; "account.follow.following" = "Segui già"; diff --git a/IceCubesApp/Resources/Localization/ja.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/ja.lproj/Localizable.strings index 62f67082..f273e111 100644 --- a/IceCubesApp/Resources/Localization/ja.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/ja.lproj/Localizable.strings @@ -247,6 +247,12 @@ "account.edit.post-settings.privacy" = "デフォルトのプライバシー"; "account.edit.post-settings.section-title" = "投稿設定"; "account.edit.post-settings.sensitive" = "センシティブな内容"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "お気に入りされた"; "account.follow.follow" = "フォロー"; "account.follow.following" = "フォロー中"; diff --git a/IceCubesApp/Resources/Localization/ko.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/ko.lproj/Localizable.strings index 63281193..5c452713 100644 --- a/IceCubesApp/Resources/Localization/ko.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/ko.lproj/Localizable.strings @@ -248,6 +248,12 @@ "account.edit.post-settings.privacy" = "기본 공개 범위"; "account.edit.post-settings.section-title" = "글 설정"; "account.edit.post-settings.sensitive" = "민감한 콘텐츠"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "좋아요한 사용자"; "account.follow.follow" = "팔로우"; "account.follow.following" = "팔로우 중"; diff --git a/IceCubesApp/Resources/Localization/nb.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/nb.lproj/Localizable.strings index 228b9c66..2fa91dd3 100644 --- a/IceCubesApp/Resources/Localization/nb.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/nb.lproj/Localizable.strings @@ -247,6 +247,12 @@ "account.edit.post-settings.privacy" = "Standard personvern"; "account.edit.post-settings.section-title" = "Innstillinger for innlegg"; "account.edit.post-settings.sensitive" = "Sensitivt innhold"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Favoritt av"; "account.follow.follow" = "Følg"; "account.follow.following" = "Følger"; diff --git a/IceCubesApp/Resources/Localization/nl.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/nl.lproj/Localizable.strings index 5e569b50..1a163ee3 100644 --- a/IceCubesApp/Resources/Localization/nl.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/nl.lproj/Localizable.strings @@ -244,6 +244,12 @@ "account.edit.post-settings.privacy" = "Standaardprivacy"; "account.edit.post-settings.section-title" = "Postinstellingen"; "account.edit.post-settings.sensitive" = "Gevoelige inhoud"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Gefavoriet"; "account.follow.follow" = "Volg"; "account.follow.following" = "Volgend"; diff --git a/IceCubesApp/Resources/Localization/pl.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/pl.lproj/Localizable.strings index 4ec4db5e..7193b598 100644 --- a/IceCubesApp/Resources/Localization/pl.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/pl.lproj/Localizable.strings @@ -245,6 +245,12 @@ "account.edit.post-settings.privacy" = "Prywatność domyślna"; "account.edit.post-settings.section-title" = "Ustawienia postów"; "account.edit.post-settings.sensitive" = "Treści wrażliwe"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Polubione przez"; "account.follow.follow" = "Obserwuj"; "account.follow.following" = "Obserwuję"; diff --git a/IceCubesApp/Resources/Localization/pt-BR.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/pt-BR.lproj/Localizable.strings index 54b08f8c..c34b2a9d 100644 --- a/IceCubesApp/Resources/Localization/pt-BR.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/pt-BR.lproj/Localizable.strings @@ -247,6 +247,12 @@ "account.edit.post-settings.privacy" = "Privacidade padrão"; "account.edit.post-settings.section-title" = "Configuração de postagem"; "account.edit.post-settings.sensitive" = "Conteúdo Sensível"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Favoritado por"; "account.follow.follow" = "Seguir"; "account.follow.following" = "Seguindo"; diff --git a/IceCubesApp/Resources/Localization/tr.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/tr.lproj/Localizable.strings index d0e95312..6165a963 100644 --- a/IceCubesApp/Resources/Localization/tr.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/tr.lproj/Localizable.strings @@ -247,6 +247,12 @@ "account.edit.post-settings.privacy" = "Varsayılan gizlilik"; "account.edit.post-settings.section-title" = "Gönderi ayarları"; "account.edit.post-settings.sensitive" = "Hassas içerik"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Şunlar tarafından favorilendi"; "account.follow.follow" = "Takip Et"; "account.follow.following" = "Takip Edilen"; diff --git a/IceCubesApp/Resources/Localization/uk.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/uk.lproj/Localizable.strings index ede52ec8..a49f03a8 100644 --- a/IceCubesApp/Resources/Localization/uk.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/uk.lproj/Localizable.strings @@ -248,6 +248,12 @@ "account.edit.post-settings.privacy" = "Приватність за замовчуванням"; "account.edit.post-settings.section-title" = "Налаштування допису"; "account.edit.post-settings.sensitive" = "Делікатний вміст"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "Вподобали"; "account.follow.follow" = "Підписатися"; "account.follow.following" = "Підписаний"; diff --git a/IceCubesApp/Resources/Localization/zh-Hans.lproj/Localizable.strings b/IceCubesApp/Resources/Localization/zh-Hans.lproj/Localizable.strings index 1e3d29d1..06e752c2 100644 --- a/IceCubesApp/Resources/Localization/zh-Hans.lproj/Localizable.strings +++ b/IceCubesApp/Resources/Localization/zh-Hans.lproj/Localizable.strings @@ -245,6 +245,12 @@ "account.edit.post-settings.privacy" = "默认隐私设置"; "account.edit.post-settings.section-title" = "嘟文设置"; "account.edit.post-settings.sensitive" = "敏感内容"; + +"account.edit.metadata-section-title" = "Profile Metadata"; +"account.edit.metadata-name-placeholder" = "Label"; +"account.edit.metadata-value-placeholder" = "Content"; +"account.edit.add-metadata-button" = "Add a new metadata"; + "account.favorited-by" = "同样喜欢的有"; "account.follow.follow" = "关注"; "account.follow.following" = "正在关注"; diff --git a/Packages/Account/Sources/Account/Edit/EditAccountView.swift b/Packages/Account/Sources/Account/Edit/EditAccountView.swift index ae6da2b3..f622f8e2 100644 --- a/Packages/Account/Sources/Account/Edit/EditAccountView.swift +++ b/Packages/Account/Sources/Account/Edit/EditAccountView.swift @@ -19,12 +19,14 @@ public struct EditAccountView: View { loadingSection } else { aboutSections + fieldsSection postSettingsSection accountSection } } .scrollContentBackground(.hidden) .background(theme.secondaryBackgroundColor) + .scrollDismissesKeyboard(.immediately) .navigationTitle("account.edit.navigation-title") .navigationBarTitleDisplayMode(.inline) .toolbar { @@ -97,6 +99,33 @@ public struct EditAccountView: View { } .listRowBackground(theme.primaryBackgroundColor) } + + private var fieldsSection: some View { + Section("account.edit.metadata-section-title") { + ForEach($viewModel.fields) { $field in + VStack(alignment: .leading) { + TextField("account.edit.metadata-name-placeholder", text: $field.name) + TextField("account.edit.metadata-value-placeholder", text: $field.value) + } + } + .onDelete { indexes in + if let index = indexes.first { + viewModel.fields.remove(at: index) + } + } + if viewModel.fields.count < 4 { + Button { + withAnimation { + viewModel.fields.append(.init(name: "", value: "")) + } + } label: { + Text("account.edit.add-metadata-button") + .foregroundColor(theme.tintColor) + } + } + } + .listRowBackground(theme.primaryBackgroundColor) + } @ToolbarContentBuilder private var toolbarContent: some ToolbarContent { diff --git a/Packages/Account/Sources/Account/Edit/EditAccountViewModel.swift b/Packages/Account/Sources/Account/Edit/EditAccountViewModel.swift index ca99756e..06f52691 100644 --- a/Packages/Account/Sources/Account/Edit/EditAccountViewModel.swift +++ b/Packages/Account/Sources/Account/Edit/EditAccountViewModel.swift @@ -4,6 +4,18 @@ import SwiftUI @MainActor class EditAccountViewModel: ObservableObject { + + class FieldEditViewModel: ObservableObject, Identifiable { + let id = UUID().uuidString + @Published var name: String = "" + @Published var value: String = "" + + init(name: String, value: String) { + self.name = name + self.value = value + } + } + public var client: Client? @Published var displayName: String = "" @@ -13,6 +25,7 @@ class EditAccountViewModel: ObservableObject { @Published var isBot: Bool = false @Published var isLocked: Bool = false @Published var isDiscoverable: Bool = false + @Published var fields: [FieldEditViewModel] = [] @Published var isLoading: Bool = true @Published var isSaving: Bool = false @@ -31,6 +44,7 @@ class EditAccountViewModel: ObservableObject { isBot = account.bot isLocked = account.locked isDiscoverable = account.discoverable ?? false + fields = account.fields.map{ .init(name: $0.name, value: $0.value.asRawText )} withAnimation { isLoading = false } @@ -40,14 +54,14 @@ class EditAccountViewModel: ObservableObject { func save() async { isSaving = true do { - let response = - try await client?.patch(endpoint: Accounts.updateCredentials(displayName: displayName, - note: note, - privacy: postPrivacy, - isSensitive: isSensitive, - isBot: isBot, - isLocked: isLocked, - isDiscoverable: isDiscoverable)) + let data = UpdateCredentialsData(displayName: displayName, + note: note, + source: .init(privacy: postPrivacy, sensitive: isSensitive), + bot: isBot, + locked: isLocked, + discoverable: isDiscoverable, + fieldsAttributes: fields.map{ .init(name: $0.name, value: $0.value)}) + let response = try await client?.patch(endpoint: Accounts.updateCredentials(json: data)) if response?.statusCode != 200 { saveError = true } diff --git a/Packages/Models/Sources/Models/Account.swift b/Packages/Models/Sources/Models/Account.swift index e4ce06ba..f95b31e4 100644 --- a/Packages/Models/Sources/Models/Account.swift +++ b/Packages/Models/Sources/Models/Account.swift @@ -13,7 +13,8 @@ public final class Account: Codable, Identifiable, Hashable, Sendable, Equatable lhs.fields == rhs.fields && lhs.lastStatusAt == rhs.lastStatusAt && lhs.discoverable == rhs.discoverable && - lhs.bot == rhs.bot + lhs.bot == rhs.bot && + lhs.locked == rhs.locked } public func hash(into hasher: inout Hasher) { diff --git a/Packages/Network/Sources/Network/Endpoint/Accounts.swift b/Packages/Network/Sources/Network/Endpoint/Accounts.swift index db73d8d7..e5479f85 100644 --- a/Packages/Network/Sources/Network/Endpoint/Accounts.swift +++ b/Packages/Network/Sources/Network/Endpoint/Accounts.swift @@ -8,13 +8,7 @@ public enum Accounts: Endpoint { case followedTags case featuredTags(id: String) case verifyCredentials - case updateCredentials(displayName: String, - note: String, - privacy: Visibility, - isSensitive: Bool, - isBot: Bool, - isLocked: Bool, - isDiscoverable: Bool) + case updateCredentials(json: UpdateCredentialsData) case statuses(id: String, sinceId: String?, tag: String?, @@ -126,17 +120,6 @@ public enum Accounts: Endpoint { case let .bookmarks(sinceId): guard let sinceId else { return nil } return [.init(name: "max_id", value: sinceId)] - case let .updateCredentials(displayName, note, privacy, - isSensitive, isBot, isLocked, isDiscoverable): - var params: [URLQueryItem] = [] - params.append(.init(name: "display_name", value: displayName)) - params.append(.init(name: "note", value: note)) - params.append(.init(name: "source[privacy]", value: privacy.rawValue)) - params.append(.init(name: "source[sensitive]", value: isSensitive ? "true" : "false")) - params.append(.init(name: "bot", value: isBot ? "true" : "false")) - params.append(.init(name: "locked", value: isLocked ? "true" : "false")) - params.append(.init(name: "discoverable", value: isDiscoverable ? "true" : "false")) - return params default: return nil } @@ -148,6 +131,8 @@ public enum Accounts: Endpoint { return json case let .relationshipNote(_, json): return json + case let .updateCredentials(json): + return json default: return nil } @@ -169,3 +154,57 @@ public struct RelationshipNoteData: Encodable, Sendable { self.comment = comment } } + +public struct UpdateCredentialsData: Encodable, Sendable { + public struct SourceData: Encodable, Sendable { + public let privacy: Visibility + public let sensitive: Bool + + public init(privacy: Visibility, sensitive: Bool) { + self.privacy = privacy + self.sensitive = sensitive + } + } + + public struct FieldData: Encodable, Sendable { + public let name: String + public let value: String + + public init(name: String, value: String) { + self.name = name + self.value = value + } + } + + public let displayName: String + public let note: String + public let source: SourceData + public let bot: Bool + public let locked: Bool + public let discoverable: Bool + public let fieldsAttributes: [String: FieldData] + + public init(displayName: String, + note: String, + source: UpdateCredentialsData.SourceData, + bot: Bool, + locked: Bool, + discoverable: Bool, + fieldsAttributes: [FieldData]) { + self.displayName = displayName + self.note = note + self.source = source + self.bot = bot + self.locked = locked + self.discoverable = discoverable + + var fieldAttributes: [String: FieldData] = [:] + var index: Int = 0 + for fieldsAttribute in fieldsAttributes { + fieldAttributes[String(index)] = fieldsAttribute + index += 1 + } + self.fieldsAttributes = fieldAttributes + } + +}