diff --git a/Model/Accounts/AccountsModel.swift b/Model/Accounts/AccountsModel.swift index f9c92c62..f1ee1de9 100644 --- a/Model/Accounts/AccountsModel.swift +++ b/Model/Accounts/AccountsModel.swift @@ -54,6 +54,15 @@ final class AccountsModel: ObservableObject { ) } + func configureAccount() { + if let account = lastUsed ?? + InstancesModel.lastUsed?.anonymousAccount ?? + InstancesModel.all.first?.anonymousAccount + { + setCurrent(account) + } + } + func setCurrent(_ account: Account! = nil) { guard account != current else { return diff --git a/Model/Accounts/InstancesModel.swift b/Model/Accounts/InstancesModel.swift index 96547cd7..f4dd41a6 100644 --- a/Model/Accounts/InstancesModel.swift +++ b/Model/Accounts/InstancesModel.swift @@ -14,7 +14,7 @@ final class InstancesModel: ObservableObject { return InstancesModel.find(id) } - var lastUsed: Instance? { + static var lastUsed: Instance? { guard let id = Defaults[.lastInstanceID] else { return nil } diff --git a/Model/InstancesManifest.swift b/Model/InstancesManifest.swift index 1c47dbf7..5818b607 100644 --- a/Model/InstancesManifest.swift +++ b/Model/InstancesManifest.swift @@ -31,7 +31,7 @@ final class InstancesManifest: Service, ObservableObject { guard let country = country else { accounts.publicAccount = nil if asCurrent { - accounts.setCurrent(nil) + accounts.configureAccount() } return } diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index 8e282e19..0f83405f 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -174,12 +174,8 @@ struct YatteeApp: App { } #endif - if Defaults[.lastAccountID] != "public", - let account = accounts.lastUsed ?? - instances.lastUsed?.anonymousAccount ?? - InstancesModel.all.first?.anonymousAccount - { - accounts.setCurrent(account) + if Defaults[.lastAccountID] != "public" { + accounts.configureAccount() } let countryOfPublicInstances = Defaults[.countryOfPublicInstances]