mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 13:33:42 +00:00
Improve switching between public and private locations
This commit is contained in:
parent
78c50bef45
commit
62f18e8506
@ -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
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ extension Defaults.Keys {
|
||||
static let lastAccountID = Key<Account.ID?>("lastAccountID")
|
||||
static let lastInstanceID = Key<Instance.ID?>("lastInstanceID")
|
||||
static let lastUsedPlaylistID = Key<Playlist.ID?>("lastPlaylistID")
|
||||
static let lastAccountIsPublic = Key<Bool>("lastAccountIsPublic", default: false)
|
||||
|
||||
static let sponsorBlockInstance = Key<String>("sponsorBlockInstance", default: "https://sponsor.ajay.app")
|
||||
static let sponsorBlockCategories = Key<Set<String>>("sponsorBlockCategories", default: Set(SponsorBlockAPI.categories))
|
||||
|
@ -174,7 +174,7 @@ struct YatteeApp: App {
|
||||
}
|
||||
#endif
|
||||
|
||||
if Defaults[.lastAccountID] != "public" {
|
||||
if !Defaults[.lastAccountIsPublic] {
|
||||
accounts.configureAccount()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user