summaryrefslogtreecommitdiff
path: root/Sora/Data/Settings/SettingsManager.swift
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-06-16 10:02:44 -0700
committerFuwn <[email protected]>2025-06-16 10:02:44 -0700
commit375d5b504634915bb17c932ee49aee99036275d0 (patch)
treeb6745fc4134e639895c13160794982e9f0d4694a /Sora/Data/Settings/SettingsManager.swift
parentfeat: Development commit (diff)
downloadsora-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.swift26
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