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 | 67 |
1 files changed, 66 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 fbf377466..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 @@ -38,6 +38,7 @@ import app.fedilab.android.client.endpoints.MastodonAccountsService; import app.fedilab.android.client.entities.api.Account; import app.fedilab.android.client.entities.api.Accounts; import app.fedilab.android.client.entities.api.Domains; +import app.fedilab.android.client.entities.api.FamiliarFollowers; import app.fedilab.android.client.entities.api.FeaturedTag; import app.fedilab.android.client.entities.api.Field; import app.fedilab.android.client.entities.api.Filter; @@ -90,6 +91,7 @@ public class AccountsVM extends AndroidViewModel { private MutableLiveData<List<IdentityProof>> identityProofListMutableLiveData; private MutableLiveData<RelationShip> relationShipMutableLiveData; private MutableLiveData<List<RelationShip>> relationShipListMutableLiveData; + private MutableLiveData<List<FamiliarFollowers>> familiarFollowersListMutableLiveData; private MutableLiveData<Filter> filterMutableLiveData; private MutableLiveData<List<Filter>> filterListMutableLiveData; private MutableLiveData<List<Tag>> tagListMutableLiveData; @@ -1025,6 +1027,38 @@ public class AccountsVM extends AndroidViewModel { return relationShipListMutableLiveData; } + + /** + * Obtain a list of all accounts that follow a given account, filtered for accounts you follow. + * + * @param ids {@link List} of account IDs to check + * @return {@link LiveData} containing a {@link List} of {@link FamiliarFollowers}s to given account(s) + */ + public LiveData<List<FamiliarFollowers>> getFamiliarFollowers(@NonNull String instance, String token, @NonNull List<String> ids) { + familiarFollowersListMutableLiveData = new MutableLiveData<>(); + MastodonAccountsService mastodonAccountsService = init(instance); + new Thread(() -> { + List<FamiliarFollowers> familiarFollowers = null; + Call<List<FamiliarFollowers>> familiarFollowersCall = mastodonAccountsService.getFamiliarFollowers(token, ids); + + if (familiarFollowersCall != null) { + try { + Response<List<FamiliarFollowers>> familiarFollowersResponse = familiarFollowersCall.execute(); + if (familiarFollowersResponse.isSuccessful()) { + familiarFollowers = familiarFollowersResponse.body(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + Handler mainHandler = new Handler(Looper.getMainLooper()); + List<FamiliarFollowers> finalFamiliarFollowers = familiarFollowers; + Runnable myRunnable = () -> familiarFollowersListMutableLiveData.setValue(finalFamiliarFollowers); + mainHandler.post(myRunnable); + }).start(); + return familiarFollowersListMutableLiveData; + } + /** * Search for matching accounts by username or display name. * @@ -1561,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<>(); @@ -1588,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 |