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:
parent
0cfe0041df
commit
eda79e6beb
|
@ -230,16 +230,16 @@ extension MastodonPickServerViewModel {
|
|||
|
||||
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
|
||||
guard servers.isNotEmpty else { return nil }
|
||||
|
||||
let randomServer = servers.filter {
|
||||
$0.language == language
|
||||
$0.language.lowercased() == language
|
||||
}.randomElement()
|
||||
|
||||
return randomServer
|
||||
return randomServer ?? servers.randomElement() ?? servers.first
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue