diff --git a/Model/Accounts/AccountsModel.swift b/Model/Accounts/AccountsModel.swift index f1ee1de9..2b91ded0 100644 --- a/Model/Accounts/AccountsModel.swift +++ b/Model/Accounts/AccountsModel.swift @@ -81,8 +81,12 @@ final class AccountsModel: ObservableObject { piped.setAccount(account) } - Defaults[.lastAccountID] = account.anonymous ? (account.isPublic ? "public" : nil) : account.id - Defaults[.lastInstanceID] = account.instanceID + Defaults[.lastAccountIsPublic] = account.isPublic + + if !account.isPublic { + Defaults[.lastAccountID] = account.anonymous ? nil : account.id + Defaults[.lastInstanceID] = account.instanceID + } } static func find(_ id: Account.ID) -> Account? { diff --git a/Model/InstancesManifest.swift b/Model/InstancesManifest.swift index 5818b607..a60e0da1 100644 --- a/Model/InstancesManifest.swift +++ b/Model/InstancesManifest.swift @@ -51,15 +51,24 @@ final class InstancesManifest: Service, ObservableObject { func changePublicAccount(_ accounts: AccountsModel, settings: SettingsModel) { instancesList.load().onSuccess { response in if let instances: [ManifestedInstance] = response.typedContent() { - let countryInstances = instances.filter { $0.country == Defaults[.countryOfPublicInstances] } + var countryInstances = instances.filter { $0.country == Defaults[.countryOfPublicInstances] } let region = countryInstances.first?.region ?? "Europe" var regionInstances = instances.filter { $0.region == region } if let publicAccountUrl = accounts.publicAccount?.url { + countryInstances = countryInstances.filter { $0.url.absoluteString != publicAccountUrl } regionInstances = regionInstances.filter { $0.url.absoluteString != publicAccountUrl } } - guard let instance = regionInstances.randomElement() else { + var instance: ManifestedInstance? + + if accounts.current?.isPublic ?? false { + instance = regionInstances.randomElement() + } else { + instance = countryInstances.randomElement() ?? regionInstances.randomElement() + } + + guard let instance = instance else { settings.presentAlert(title: "Could not change location", message: "No locations available at the moment") return } diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 3920d228..178e792a 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -26,6 +26,7 @@ extension Defaults.Keys { static let lastAccountID = Key("lastAccountID") static let lastInstanceID = Key("lastInstanceID") static let lastUsedPlaylistID = Key("lastPlaylistID") + static let lastAccountIsPublic = Key("lastAccountIsPublic", default: false) static let sponsorBlockInstance = Key("sponsorBlockInstance", default: "https://sponsor.ajay.app") static let sponsorBlockCategories = Key>("sponsorBlockCategories", default: Set(SponsorBlockAPI.categories)) diff --git a/Shared/YatteeApp.swift b/Shared/YatteeApp.swift index 0f83405f..d6e19d15 100644 --- a/Shared/YatteeApp.swift +++ b/Shared/YatteeApp.swift @@ -174,7 +174,7 @@ struct YatteeApp: App { } #endif - if Defaults[.lastAccountID] != "public" { + if !Defaults[.lastAccountIsPublic] { accounts.configureAccount() }