CommonComposeViewModel: filter all unrelated autocomplete suggestions

main
Alibek Omarov 4 years ago
parent f32bfc2ae6
commit 51083556f1
  1. 2
      app/src/main/java/com/keylesspalace/tusky/adapter/ComposeAutoCompleteAdapter.java
  2. 6
      app/src/main/java/com/keylesspalace/tusky/components/common/CommonComposeViewModel.kt

@ -267,7 +267,7 @@ public class ComposeAutoCompleteAdapter extends BaseAdapter
}
public final static class AccountResult extends AutocompleteResult {
private final Account account;
public final Account account;
public AccountResult(Account account) {
this.account = account;

@ -252,9 +252,13 @@ open class CommonComposeViewModel(
when (token[0]) {
'@' -> {
return try {
api.searchAccounts(query = token.substring(1), limit = 10)
val acct = token.substring(1)
api.searchAccounts(query = acct, resolve = true, limit = 10)
.blockingGet()
.map { ComposeAutoCompleteAdapter.AccountResult(it) }
.filter {
it.account.username.startsWith(acct, ignoreCase = true)
}
} catch (e: Throwable) {
Log.e(TAG, String.format("Autocomplete search for %s failed.", token), e)
emptyList()

Loading…
Cancel
Save