Skip to content

Commit

Permalink
Add methods to check if all users or members are cached
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastian committed Sep 27, 2020
1 parent 954ac2a commit 2eeff95
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions javacord-api/src/main/java/org/javacord/api/DiscordApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,15 @@ default CompletableFuture<Void> updateAvatar(InputStream avatar, String fileType
*/
boolean isUserCacheEnabled();

/**
* Checks if all users of available servers are in the cache.
*
* @return Whether or not all users of available servers are in the cache.
*/
default boolean hasAllUsersInCache() {
return !getServers().stream().anyMatch(Server::hasAllMembersInCache);
}

/**
* Gets a collection with all currently cached users.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ default CompletableFuture<Integer> pruneMembers(int days) {
*/
CompletableFuture<Collection<RichInvite>> getInvites();

/**
* Checks if all members of the server are in the cache.
*
* @return Whether or not all members of the server are in the cache.
*/
boolean hasAllMembersInCache();

/**
* Gets a collection with all members of the server.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,11 @@ public CompletableFuture<Collection<RichInvite>> getInvites() {
});
}

@Override
public boolean hasAllMembersInCache() {
return getRealMembers().size() >= getMemberCount();
}

@Override
public Set<User> getMembers() {
return api.getEntityCache().get().getMemberCache()
Expand Down

0 comments on commit 2eeff95

Please sign in to comment.