Use server language preference for default search token suggestion

This commit is contained in:
Shadowfacts 2023-11-10 14:42:48 -05:00
parent 1c36312850
commit 380f878d81
1 changed files with 5 additions and 4 deletions

View File

@ -65,12 +65,13 @@ class MastodonSearchController: UISearchController {
searchText.isEmpty || $0.contains(searchText) searchText.isEmpty || $0.contains(searchText)
})) }))
// TODO: use default language from preferences
var langSuggestions = [String]() var langSuggestions = [String]()
if searchText.isEmpty || "language:en".contains(searchText) { let defaultLanguage = searchResultsController.mastodonController.accountPreferences.serverDefaultLanguage ?? "en"
langSuggestions.append("language:en") let languageToken = "language:\(defaultLanguage)"
if searchText.isEmpty || languageToken.contains(searchText) {
langSuggestions.append(languageToken)
} }
if searchText != "en", if searchText != defaultLanguage,
let match = languageRegex.firstMatch(in: searchText, range: NSRange(location: 0, length: searchText.utf16.count)) { let match = languageRegex.firstMatch(in: searchText, range: NSRange(location: 0, length: searchText.utf16.count)) {
let identifier = (searchText as NSString).substring(with: match.range(at: 1)) let identifier = (searchText as NSString).substring(with: match.range(at: 1))
if #available(iOS 16.0, *) { if #available(iOS 16.0, *) {