Fix language-based random server-selection (#690)

During testing on device I noticed, that "next" didn't work. The reason was that I used the wrong language code. In case there's no server in my language, the server gets totally randomly selected.
This commit is contained in:
Nathan Mattes 2023-01-06 16:07:39 +01:00
parent 0cfe0041df
commit eda79e6beb
1 changed files with 3 additions and 3 deletions

View File

@ -230,16 +230,16 @@ extension MastodonPickServerViewModel {
func chooseRandomServer() -> Mastodon.Entity.Server? { func chooseRandomServer() -> Mastodon.Entity.Server? {
guard let language = Locale.preferredLanguages.first?.lowercased() else { return nil } let language = Locale.autoupdatingCurrent.languageCode?.lowercased() ?? "en"
let servers = indexedServers.value let servers = indexedServers.value
guard servers.isNotEmpty else { return nil } guard servers.isNotEmpty else { return nil }
let randomServer = servers.filter { let randomServer = servers.filter {
$0.language == language $0.language.lowercased() == language
}.randomElement() }.randomElement()
return randomServer return randomServer ?? servers.randomElement() ?? servers.first
} }
} }