Don't allow duplicate accounts on launch. Issue #2448
This commit is contained in:
parent
bad21330f3
commit
0708ffcec8
|
@ -165,6 +165,15 @@ public final class AccountManager: UnreadCountProvider {
|
||||||
NotificationCenter.default.post(name: .UserDidDeleteAccount, object: self, userInfo: userInfo)
|
NotificationCenter.default.post(name: .UserDidDeleteAccount, object: self, userInfo: userInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func duplicateServiceAccount(type: AccountType, username: String?) -> Bool {
|
||||||
|
for account in accounts {
|
||||||
|
if account.type == type && username == account.username {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
public func existingAccount(with accountID: String) -> Account? {
|
public func existingAccount(with accountID: String) -> Account? {
|
||||||
return accountsDictionary[accountID]
|
return accountsDictionary[accountID]
|
||||||
}
|
}
|
||||||
|
@ -350,16 +359,24 @@ private extension AccountManager {
|
||||||
print("Error reading Accounts folder: \(error)")
|
print("Error reading Accounts folder: \(error)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filenames = filenames?.sorted()
|
||||||
|
|
||||||
filenames?.forEach { (oneFilename) in
|
filenames?.forEach { (oneFilename) in
|
||||||
guard oneFilename != defaultAccountFolderName else {
|
guard oneFilename != defaultAccountFolderName else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let oneAccount = loadAccount(oneFilename) {
|
if let oneAccount = loadAccount(oneFilename) {
|
||||||
accountsDictionary[oneAccount.accountID] = oneAccount
|
if !duplicateServiceAccount(oneAccount) {
|
||||||
|
accountsDictionary[oneAccount.accountID] = oneAccount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func duplicateServiceAccount(_ account: Account) -> Bool {
|
||||||
|
return duplicateServiceAccount(type: account.type, username: account.username)
|
||||||
|
}
|
||||||
|
|
||||||
func sortByName(_ accounts: [Account]) -> [Account] {
|
func sortByName(_ accounts: [Account]) -> [Account] {
|
||||||
// LocalAccount is first.
|
// LocalAccount is first.
|
||||||
|
|
Loading…
Reference in New Issue