diff options
Diffstat (limited to 'app/src/main/java/app/fedilab/android/viewmodel/mastodon/AccountsVM.java')
-rw-r--r-- | app/src/main/java/app/fedilab/android/viewmodel/mastodon/AccountsVM.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AccountsVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AccountsVM.java index e9f23ec1a..1567a5024 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AccountsVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/AccountsVM.java @@ -1595,7 +1595,7 @@ public class AccountsVM extends AndroidViewModel { * Accounts the user has had past positive interactions with, but is not yet following. * * @param limit Maximum number of results to return. Defaults to 40. - * @return {@link LiveData} containing a {@link List} of {@link Account}s + * @return {@link LiveData} containing a {@link List} of {@link Suggestion}s */ public LiveData<Suggestions> getSuggestions(@NonNull String instance, String token, String limit) { suggestionsMutableLiveData = new MutableLiveData<>(); @@ -1622,6 +1622,37 @@ public class AccountsVM extends AndroidViewModel { } /** + * List accounts visible in the directory. + * + * @param limit Maximum number of results to return. Defaults to 40. + * @return {@link LiveData} containing a {@link List} of {@link Account}s + */ + public LiveData<Accounts> getDirectory(@NonNull String instance, String token, Integer offset, Integer limit, String order, Boolean local) { + accountsMutableLiveData = new MutableLiveData<>(); + MastodonAccountsService mastodonAccountsService = init(instance); + new Thread(() -> { + Call<List<Account>> accountsCall = mastodonAccountsService.getDirectory(token, offset, limit, order, local); + Accounts accounts = new Accounts(); + + if (accountsCall != null) { + try { + Response<List<Account>> directoryResponse = accountsCall.execute(); + if (directoryResponse.isSuccessful()) { + accounts.pagination = MastodonHelper.getOffSetPagination(directoryResponse.headers()); + accounts.accounts = directoryResponse.body(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + Handler mainHandler = new Handler(Looper.getMainLooper()); + Runnable myRunnable = () -> accountsMutableLiveData.setValue(accounts); + mainHandler.post(myRunnable); + }).start(); + return accountsMutableLiveData; + } + + /** * Remove an account from follow suggestions. * * @param accountId id of the account in the database to be removed from suggestions |