CommonComposeViewModel: filter all unrelated autocomplete suggestions

This commit is contained in:
Alibek Omarov 2020-10-05 19:51:56 +03:00
parent 3fff54c1f4
commit 629a336e7e
2 changed files with 6 additions and 2 deletions

View File

@ -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;

View File

@ -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()