diff options
| author | Fuwn <[email protected]> | 2025-06-16 10:02:44 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-06-16 10:02:44 -0700 |
| commit | 375d5b504634915bb17c932ee49aee99036275d0 (patch) | |
| tree | b6745fc4134e639895c13160794982e9f0d4694a /Sora/Data/Settings/SettingsManager.swift | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-375d5b504634915bb17c932ee49aee99036275d0.tar.xz sora-testing-375d5b504634915bb17c932ee49aee99036275d0.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Data/Settings/SettingsManager.swift')
| -rw-r--r-- | Sora/Data/Settings/SettingsManager.swift | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Sora/Data/Settings/SettingsManager.swift b/Sora/Data/Settings/SettingsManager.swift index c824cff..39dbfee 100644 --- a/Sora/Data/Settings/SettingsManager.swift +++ b/Sora/Data/Settings/SettingsManager.swift @@ -201,12 +201,34 @@ class SettingsManager: ObservableObject { // swiftlint:disable:this type_body_l } } + private func mergedCredentialValues<Value>( + extract: (BooruProviderCredentials) -> Value, + isDefault: (Value) -> Bool + ) -> [BooruProvider: Value] { + providerCredentials.reduce(into: [BooruProvider: Value]()) { dictionary, credentials in + let key = credentials.provider + let value = extract(credentials) + + if dictionary[key] == nil { + dictionary[key] = value + } else if isDefault(dictionary[key]!) && !isDefault(value) { + dictionary[key] = value + } + } + } + var providerAPIKeys: [BooruProvider: String] { - Dictionary(uniqueKeysWithValues: providerCredentials.map { ($0.provider, $0.apiKey) }) + mergedCredentialValues( + extract: { $0.apiKey }, + isDefault: { $0.isEmpty } + ) } var providerUserIDs: [BooruProvider: Int] { - Dictionary(uniqueKeysWithValues: providerCredentials.map { ($0.provider, $0.userID) }) + mergedCredentialValues( + extract: { $0.userID }, + isDefault: { $0 == 0 } + ) } // MARK: - Initialisation |