mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Improve switching between public and private locations
This commit is contained in:
@@ -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? {
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user