diff --git a/src/main/java/net/dv8tion/jda/api/JDA.java b/src/main/java/net/dv8tion/jda/api/JDA.java index 9099531277..659a7929dd 100644 --- a/src/main/java/net/dv8tion/jda/api/JDA.java +++ b/src/main/java/net/dv8tion/jda/api/JDA.java @@ -970,11 +970,11 @@ default List getUsersByName(@Nonnull String name, boolean ignoreCase) /** * Attempts to retrieve a {@link net.dv8tion.jda.api.entities.User User} object based on the provided id. - *
This first calls {@link #getUserById(long)}, and if that returns {@code null} or the cache is inconsistent due to disabled intents then a request - * is made to the Discord servers. * - *

When the both {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_PRESENCES GUILD_PRESENCES} and {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intents - * are disabled this will always make a request even if the user is cached. You can use {@link #retrieveUserById(String, boolean)} to disable this behavior. + *

If {@link #getUserById(long)} is cached, this will directly return the user in a completed {@link RestAction} without making a request. + * When both {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_PRESENCES GUILD_PRESENCES} and {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intents + * are disabled this will always make a request even if the user is cached. + * You can use {@link CacheRestAction#useCache(boolean) action.useCache(false)} to force an update. * *

The returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} can encounter the following Discord errors: *

* - * @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.User User} + * @return {@link CacheRestAction} - Type: {@link User} *
On request, gets the User with id matching provided id from Discord. */ @Nonnull @CheckReturnValue - default RestAction retrieveUserById(@Nonnull String id) + default CacheRestAction retrieveUserById(@Nonnull String id) { - return retrieveUserById(id, true); + return retrieveUserById(MiscUtil.parseSnowflake(id)); } /** * Attempts to retrieve a {@link net.dv8tion.jda.api.entities.User User} object based on the provided id. - *
This first calls {@link #getUserById(long)}, and if that returns {@code null} or the cache is inconsistent due to disabled intents then a request - * is made to the Discord servers. * - *

When the both {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_PRESENCES GUILD_PRESENCES} and {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intents - * are disabled this will always make a request even if the user is cached. You can use {@link #retrieveUserById(String, boolean)} to disable this behavior. + *

If {@link #getUserById(long)} is cached, this will directly return the user in a completed {@link RestAction} without making a request. + * When both {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_PRESENCES GUILD_PRESENCES} and {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} intents + * are disabled this will always make a request even if the user is cached. + * You can use {@link CacheRestAction#useCache(boolean) action.useCache(false)} to force an update. * *

The returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} can encounter the following Discord errors: *

    @@ -1023,87 +1020,14 @@ default RestAction retrieveUserById(@Nonnull String id) *
* * @param id - * The id of the requested {@link net.dv8tion.jda.api.entities.User User}. - * - * @throws net.dv8tion.jda.api.exceptions.AccountTypeException - * This endpoint is {@link AccountType#BOT} only. + * The id of the requested {@link User}. * - * @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.User User} + * @return {@link CacheRestAction} - Type: {@link User} *
On request, gets the User with id matching provided id from Discord. */ @Nonnull @CheckReturnValue - default RestAction retrieveUserById(long id) - { - return retrieveUserById(id, true); - } - - /** - * Attempts to retrieve a {@link net.dv8tion.jda.api.entities.User User} object based on the provided id. - *
If both {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} and {@link GatewayIntent#GUILD_PRESENCES GUILD_PRESENCES} intents are disabled - * this method will update the cached user unless the {@code update} parameter is {@code false}. - *
If either of those intents is enabled, this will immediately provide the cached user if possible. - * - *

The returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} can encounter the following Discord errors: - *

    - *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_USER ErrorResponse.UNKNOWN_USER} - *
    Occurs when the provided id does not refer to a {@link net.dv8tion.jda.api.entities.User User} - * known by Discord. Typically occurs when developers provide an incomplete id (cut short).
  • - *
- * - * @param id - * The id of the requested {@link net.dv8tion.jda.api.entities.User User}. - * @param update - * Whether JDA should perform a request even if the member is already cached to update properties such as the name - * - * @throws net.dv8tion.jda.api.exceptions.AccountTypeException - * This endpoint is {@link AccountType#BOT} only. - * - * @throws java.lang.NumberFormatException - * If the provided {@code id} cannot be parsed by {@link Long#parseLong(String)} - * @throws java.lang.IllegalArgumentException - *
    - *
  • If the provided id String is null.
  • - *
  • If the provided id String is empty.
  • - *
- * - * @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.User User} - *
On request, gets the User with id matching provided id from Discord. - */ - @Nonnull - @CheckReturnValue - default RestAction retrieveUserById(@Nonnull String id, boolean update) - { - return retrieveUserById(MiscUtil.parseSnowflake(id), update); - } - - /** - * Attempts to retrieve a {@link net.dv8tion.jda.api.entities.User User} object based on the provided id. - *
If both {@link GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} and {@link GatewayIntent#GUILD_PRESENCES GUILD_PRESENCES} intents are disabled - * this method will update the cached user unless the {@code update} parameter is {@code false}. - *
If either of those intents is enabled, this will immediately provide the cached user if possible. - * - *

The returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} can encounter the following Discord errors: - *

    - *
  • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_USER ErrorResponse.UNKNOWN_USER} - *
    Occurs when the provided id does not refer to a {@link net.dv8tion.jda.api.entities.User User} - * known by Discord. Typically occurs when developers provide an incomplete id (cut short).
  • - *
- * - * @param id - * The id of the requested {@link net.dv8tion.jda.api.entities.User User}. - * @param update - * Whether JDA should perform a request even if the member is already cached to update properties such as the name - * - * @throws net.dv8tion.jda.api.exceptions.AccountTypeException - * This endpoint is {@link AccountType#BOT} only. - * - * @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.User User} - *
On request, gets the User with id matching provided id from Discord. - */ - @Nonnull - @CheckReturnValue - RestAction retrieveUserById(long id, boolean update); + CacheRestAction retrieveUserById(long id); /** * {@link net.dv8tion.jda.api.utils.cache.SnowflakeCacheView SnowflakeCacheView} of @@ -1366,6 +1290,9 @@ default PrivateChannel getPrivateChannelById(long id) *
This will fail with {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_USER UNKNOWN_USER} * if the user does not exist. * + *

If the channel is cached, this will directly return the channel in a completed {@link RestAction} without making a request. + * You can use {@link CacheRestAction#useCache(boolean) action.useCache(false)} to force an update. + * *

Example

*
{@code
      * public void sendMessage(JDA jda, long userId, String content) {
@@ -1381,13 +1308,13 @@ default PrivateChannel getPrivateChannelById(long id)
      * @throws UnsupportedOperationException
      *         If the target user is the currently logged in account
      *
-     * @return {@link RestAction} - Type: {@link PrivateChannel}
+     * @return {@link CacheRestAction} - Type: {@link PrivateChannel}
      *
      * @see    User#openPrivateChannel()
      */
     @Nonnull
     @CheckReturnValue
-    RestAction openPrivateChannelById(long userId);
+    CacheRestAction openPrivateChannelById(long userId);
 
     /**
      * Opens a {@link PrivateChannel} with the provided user by id.
diff --git a/src/main/java/net/dv8tion/jda/api/entities/Guild.java b/src/main/java/net/dv8tion/jda/api/entities/Guild.java
index 08edf8bff0..a56c512aa6 100644
--- a/src/main/java/net/dv8tion/jda/api/entities/Guild.java
+++ b/src/main/java/net/dv8tion/jda/api/entities/Guild.java
@@ -2446,11 +2446,8 @@ default Task> findMembersWithRoles(@Nonnull Role... roles)
      * 
If the member is already loaded it will be retrieved from {@link #getMemberById(long)} * and immediately provided if the member information is consistent. The cache consistency directly * relies on the enabled {@link GatewayIntent GatewayIntents} as {@link GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} - * is required to keep the cache updated with the latest information. You can pass {@code update = false} to always - * return immediately if the member is cached regardless of cache consistency. - * - *

When the intent {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} - * is disabled this will always make a request even if the member is cached. You can use {@link #retrieveMember(User, boolean)} to disable this behavior. + * is required to keep the cache updated with the latest information. You can use {@link CacheRestAction#useCache(boolean) useCache(true)} to always + * make a new request, which is the default behavior if the required intents are disabled. * *

Possible {@link net.dv8tion.jda.api.exceptions.ErrorResponseException ErrorResponseExceptions} include: *

    @@ -2474,92 +2471,21 @@ default Task> findMembersWithRoles(@Nonnull Role... roles) * @see #unloadMember(long) */ @Nonnull - default RestAction retrieveMember(@Nonnull UserSnowflake user) + default CacheRestAction retrieveMember(@Nonnull UserSnowflake user) { Checks.notNull(user, "User"); return retrieveMemberById(user.getId()); } - /** - * Load the member for the specified user. - *
    If the member is already loaded it will be retrieved from {@link #getMemberById(long)} - * and immediately provided if the member information is consistent. The cache consistency directly - * relies on the enabled {@link GatewayIntent GatewayIntents} as {@link GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} - * is required to keep the cache updated with the latest information. You can pass {@code update = false} to always - * return immediately if the member is cached regardless of cache consistency. - * - *

    When the intent {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GUILD_MEMBERS} - * is disabled this will always make a request even if the member is cached. You can use {@link #retrieveMemberById(String, boolean)} to disable this behavior. - * - *

    Possible {@link net.dv8tion.jda.api.exceptions.ErrorResponseException ErrorResponseExceptions} include: - *

      - *
    • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MEMBER} - *
      The specified user is not a member of this guild
    • - * - *
    • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_USER} - *
      The specified user does not exist
    • - *
    - * - * @param id - * The user id to load the member from - * - * @throws IllegalArgumentException - * If the provided id is empty or null - * @throws NumberFormatException - * If the provided id is not a snowflake - * - * @return {@link RestAction} - Type: {@link Member} - * - * @see #pruneMemberCache() - * @see #unloadMember(long) - */ - @Nonnull - default RestAction retrieveMemberById(@Nonnull String id) - { - return retrieveMemberById(MiscUtil.parseSnowflake(id)); - } - - /** - * Load the member for the specified user. - *
    If the member is already loaded it will be retrieved from {@link #getMemberById(long)} - * and immediately provided if the member information is consistent. The cache consistency directly - * relies on the enabled {@link GatewayIntent GatewayIntents} as {@link GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} - * is required to keep the cache updated with the latest information. You can pass {@code update = false} to always - * return immediately if the member is cached regardless of cache consistency. - * - *

    When {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} - * is disabled this will always make a request even if the member is cached. You can use {@link #retrieveMemberById(long, boolean)} to disable this behavior. - * - *

    Possible {@link net.dv8tion.jda.api.exceptions.ErrorResponseException ErrorResponseExceptions} include: - *

      - *
    • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MEMBER} - *
      The specified user is not a member of this guild
    • - * - *
    • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_USER} - *
      The specified user does not exist
    • - *
    - * - * @param id - * The user id to load the member from - * - * @return {@link RestAction} - Type: {@link Member} - * - * @see #pruneMemberCache() - * @see #unloadMember(long) - */ - @Nonnull - default RestAction retrieveMemberById(long id) - { - return retrieveMemberById(id, true); - } - /** * Shortcut for {@code guild.retrieveMemberById(guild.getOwnerIdLong())}. *
    This will retrieve the current owner of the guild. * It is possible that the owner of a guild is no longer a registered discord user in which case this will fail. - * - *

    When {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} - * is disabled this will always make a request even if the member is cached. You can use {@link #retrieveOwner(boolean)} to disable this behavior. + *
    If the member is already loaded it will be retrieved from {@link #getMemberById(long)} + * and immediately provided if the member information is consistent. The cache consistency directly + * relies on the enabled {@link GatewayIntent GatewayIntents} as {@link GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} + * is required to keep the cache updated with the latest information. You can use {@link CacheRestAction#useCache(boolean) useCache(true)} to always + * make a new request, which is the default behavior if the required intents are disabled. * *

    Possible {@link net.dv8tion.jda.api.exceptions.ErrorResponseException ErrorResponseExceptions} include: *

      @@ -2580,7 +2506,7 @@ default RestAction retrieveMemberById(long id) * @see #retrieveMemberById(long) */ @Nonnull - default RestAction retrieveOwner() + default CacheRestAction retrieveOwner() { return retrieveMemberById(getOwnerIdLong()); } @@ -2590,45 +2516,8 @@ default RestAction retrieveOwner() *
      If the member is already loaded it will be retrieved from {@link #getMemberById(long)} * and immediately provided if the member information is consistent. The cache consistency directly * relies on the enabled {@link GatewayIntent GatewayIntents} as {@link GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} - * is required to keep the cache updated with the latest information. You can pass {@code update = false} to always - * return immediately if the member is cached regardless of cache consistency. - * - *

      Possible {@link net.dv8tion.jda.api.exceptions.ErrorResponseException ErrorResponseExceptions} include: - *

        - *
      • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MEMBER} - *
        The specified user is not a member of this guild
      • - * - *
      • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_USER} - *
        The specified user does not exist
      • - *
      - * - * @param user - * The user to load the member from - * @param update - * Whether JDA should perform a request even if the member is already cached to update properties such as the name - * - * @throws IllegalArgumentException - * If provided with null - * - * @return {@link RestAction} - Type: {@link Member} - * - * @see #pruneMemberCache() - * @see #unloadMember(long) - */ - @Nonnull - default RestAction retrieveMember(@Nonnull User user, boolean update) - { - Checks.notNull(user, "User"); - return retrieveMemberById(user.getId(), update); - } - - /** - * Load the member for the specified user. - *
      If the member is already loaded it will be retrieved from {@link #getMemberById(long)} - * and immediately provided if the member information is consistent. The cache consistency directly - * relies on the enabled {@link GatewayIntent GatewayIntents} as {@link GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} - * is required to keep the cache updated with the latest information. You can pass {@code update = false} to always - * return immediately if the member is cached regardless of cache consistency. + * is required to keep the cache updated with the latest information. You can use {@link CacheRestAction#useCache(boolean) useCache(true)} to always + * make a new request, which is the default behavior if the required intents are disabled. * *

      Possible {@link net.dv8tion.jda.api.exceptions.ErrorResponseException ErrorResponseExceptions} include: *

        @@ -2641,8 +2530,6 @@ default RestAction retrieveMember(@Nonnull User user, boolean update) * * @param id * The user id to load the member from - * @param update - * Whether JDA should perform a request even if the member is already cached to update properties such as the name * * @throws IllegalArgumentException * If the provided id is empty or null @@ -2655,9 +2542,9 @@ default RestAction retrieveMember(@Nonnull User user, boolean update) * @see #unloadMember(long) */ @Nonnull - default RestAction retrieveMemberById(@Nonnull String id, boolean update) + default CacheRestAction retrieveMemberById(@Nonnull String id) { - return retrieveMemberById(MiscUtil.parseSnowflake(id), update); + return retrieveMemberById(MiscUtil.parseSnowflake(id)); } /** @@ -2665,8 +2552,8 @@ default RestAction retrieveMemberById(@Nonnull String id, boolean update *
        If the member is already loaded it will be retrieved from {@link #getMemberById(long)} * and immediately provided if the member information is consistent. The cache consistency directly * relies on the enabled {@link GatewayIntent GatewayIntents} as {@link GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} - * is required to keep the cache updated with the latest information. You can pass {@code update = false} to always - * return immediately if the member is cached regardless of cache consistency. + * is required to keep the cache updated with the latest information. You can use {@link CacheRestAction#useCache(boolean) useCache(false)} to always + * make a new request, which is the default behavior if the required intents are disabled. * *

        Possible {@link net.dv8tion.jda.api.exceptions.ErrorResponseException ErrorResponseExceptions} include: *

          @@ -2679,8 +2566,6 @@ default RestAction retrieveMemberById(@Nonnull String id, boolean update * * @param id * The user id to load the member from - * @param update - * Whether JDA should perform a request even if the member is already cached to update properties such as the name * * @return {@link RestAction} - Type: {@link Member} * @@ -2688,39 +2573,7 @@ default RestAction retrieveMemberById(@Nonnull String id, boolean update * @see #unloadMember(long) */ @Nonnull - RestAction retrieveMemberById(long id, boolean update); - - /** - * Shortcut for {@code guild.retrieveMemberById(guild.getOwnerIdLong())}. - *
          This will retrieve the current owner of the guild. - * It is possible that the owner of a guild is no longer a registered discord user in which case this will fail. - * - *

          Possible {@link net.dv8tion.jda.api.exceptions.ErrorResponseException ErrorResponseExceptions} include: - *

            - *
          • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MEMBER} - *
            The specified user is not a member of this guild
          • - * - *
          • {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_USER} - *
            The specified user does not exist
          • - *
          - * - * @param update - * Whether JDA should perform a request even if the member is already cached to update properties such as the name - * - * @return {@link RestAction} - Type: {@link Member} - * - * @see #pruneMemberCache() - * @see #unloadMember(long) - * - * @see #getOwner() - * @see #getOwnerIdLong() - * @see #retrieveMemberById(long) - */ - @Nonnull - default RestAction retrieveOwner(boolean update) - { - return retrieveMemberById(getOwnerIdLong(), update); - } + CacheRestAction retrieveMemberById(long id); /** * Retrieves a list of members. diff --git a/src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java b/src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java index 4c81486a9d..2a72f8725c 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java +++ b/src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java @@ -18,6 +18,7 @@ import net.dv8tion.jda.api.managers.channel.concrete.ThreadChannelManager; import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.requests.restaction.CacheRestAction; import net.dv8tion.jda.api.utils.MiscUtil; import net.dv8tion.jda.internal.utils.Checks; @@ -324,11 +325,11 @@ default ThreadMember getThreadMemberById(String id) * @throws IllegalArgumentException * If provided with null * - * @return {@link RestAction} - Type: {@link ThreadMember} + * @return {@link CacheRestAction} - Type: {@link ThreadMember} */ @Nonnull @CheckReturnValue - default RestAction retrieveThreadMember(@Nonnull Member member) + default CacheRestAction retrieveThreadMember(@Nonnull Member member) { Checks.notNull(member, "Member"); return retrieveThreadMemberById(member.getIdLong()); @@ -346,11 +347,11 @@ default RestAction retrieveThreadMember(@Nonnull Member member) * @throws IllegalArgumentException * If provided with null * - * @return {@link RestAction} - Type: {@link ThreadMember} + * @return {@link CacheRestAction} - Type: {@link ThreadMember} */ @Nonnull @CheckReturnValue - default RestAction retrieveThreadMember(@Nonnull User user) + default CacheRestAction retrieveThreadMember(@Nonnull User user) { Checks.notNull(user, "User"); return retrieveThreadMemberById(user.getIdLong()); @@ -370,11 +371,11 @@ default RestAction retrieveThreadMember(@Nonnull User user) * @throws NumberFormatException * If the provided id is not a snowflake * - * @return {@link RestAction} - Type: {@link ThreadMember} + * @return {@link CacheRestAction} - Type: {@link ThreadMember} */ @Nonnull @CheckReturnValue - default RestAction retrieveThreadMemberById(@Nonnull String id) + default CacheRestAction retrieveThreadMemberById(@Nonnull String id) { return retrieveThreadMemberById(MiscUtil.parseSnowflake(id)); } @@ -388,11 +389,11 @@ default RestAction retrieveThreadMemberById(@Nonnull String id) * @param id * The user id to load the thread-member from * - * @return {@link RestAction} - Type: {@link ThreadMember} + * @return {@link CacheRestAction} - Type: {@link ThreadMember} */ @Nonnull @CheckReturnValue - RestAction retrieveThreadMemberById(long id); + CacheRestAction retrieveThreadMemberById(long id); /** * Retrieves the {@link ThreadMember ThreadMembers} of this thread. diff --git a/src/main/java/net/dv8tion/jda/api/entities/User.java b/src/main/java/net/dv8tion/jda/api/entities/User.java index 5fff5d6c01..26e2ede153 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/User.java +++ b/src/main/java/net/dv8tion/jda/api/entities/User.java @@ -17,7 +17,7 @@ import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.requests.restaction.CacheRestAction; import net.dv8tion.jda.api.utils.ImageProxy; import net.dv8tion.jda.api.utils.MiscUtil; import net.dv8tion.jda.internal.entities.UserSnowflakeImpl; @@ -264,17 +264,16 @@ default ImageProxy getEffectiveAvatar() /** * Loads the user's {@link User.Profile} data. * Returns a completed RestAction if this User has been retrieved using {@link JDA#retrieveUserById(long)}. + * You can use {@link CacheRestAction#useCache(boolean) useCache(false)} to force the request for a new profile with up-to-date information. * * @throws UnsupportedOperationException * If this User was created with {@link #fromId(long)} * - * @return {@link RestAction} - Type: {@link User.Profile} - * - * @since 4.3.0 + * @return {@link CacheRestAction} - Type: {@link User.Profile} */ @Nonnull @CheckReturnValue - RestAction retrieveProfile(); + CacheRestAction retrieveProfile(); /** * The "tag" for this user @@ -300,9 +299,11 @@ default ImageProxy getEffectiveAvatar() boolean hasPrivateChannel(); /** - * Opens a {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel} with this User. + * Opens a {@link PrivateChannel} with this User. *
          If a channel has already been opened with this user, it is immediately returned in the RestAction's * success consumer without contacting the Discord API. + * You can use {@link CacheRestAction#useCache(boolean) useCache(false)} to force the request for a new channel object, + * which is rarely useful since the channel id never changes. * *

          Examples

          *
          {@code
          @@ -326,14 +327,14 @@ default ImageProxy getEffectiveAvatar()
                *         If the recipient User is the currently logged in account (represented by {@link net.dv8tion.jda.api.entities.SelfUser SelfUser})
                *         or if the user was created with {@link #fromId(long)}
                *
          -     * @return {@link net.dv8tion.jda.api.requests.RestAction RestAction} - Type: {@link net.dv8tion.jda.api.entities.PrivateChannel PrivateChannel}
          +     * @return {@link CacheRestAction} - Type: {@link PrivateChannel}
                *         
          Retrieves the PrivateChannel to use to directly message this User. * * @see JDA#openPrivateChannelById(long) */ @Nonnull @CheckReturnValue - RestAction openPrivateChannel(); + CacheRestAction openPrivateChannel(); /** * Finds and collects all {@link net.dv8tion.jda.api.entities.Guild Guild} instances that contain this {@link net.dv8tion.jda.api.entities.User User} within the current {@link net.dv8tion.jda.api.JDA JDA} instance.
          diff --git a/src/main/java/net/dv8tion/jda/internal/JDAImpl.java b/src/main/java/net/dv8tion/jda/internal/JDAImpl.java index 24cb95d48f..384e9cb387 100644 --- a/src/main/java/net/dv8tion/jda/internal/JDAImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/JDAImpl.java @@ -47,6 +47,7 @@ import net.dv8tion.jda.api.requests.Request; import net.dv8tion.jda.api.requests.Response; import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.requests.restaction.CacheRestAction; import net.dv8tion.jda.api.requests.restaction.CommandCreateAction; import net.dv8tion.jda.api.requests.restaction.CommandEditAction; import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction; @@ -558,22 +559,13 @@ public List getMutualGuilds(@Nonnull Collection users) @Nonnull @Override - public RestAction retrieveUserById(@Nonnull String id) + public CacheRestAction retrieveUserById(long id) { - return retrieveUserById(MiscUtil.parseSnowflake(id)); - } - - @Nonnull - @Override - public RestAction retrieveUserById(long id, boolean update) - { - if (id == getSelfUser().getIdLong()) - return new CompletedRestAction<>(this, getSelfUser()); - - AccountTypeException.check(getAccountType(), AccountType.BOT); return new DeferredRestAction<>(this, User.class, - () -> !update || isIntent(GatewayIntent.GUILD_MEMBERS) || isIntent(GatewayIntent.GUILD_PRESENCES) ? getUserById(id) : null, + () -> isIntent(GatewayIntent.GUILD_MEMBERS) || isIntent(GatewayIntent.GUILD_PRESENCES) ? getUserById(id) : null, () -> { + if (id == getSelfUser().getIdLong()) + return new CompletedRestAction<>(this, getSelfUser()); Route.CompiledRoute route = Route.Users.GET_USER.compile(Long.toUnsignedString(id)); return new RestActionImpl<>(this, route, (response, request) -> getEntityBuilder().createUser(response.getObject())); @@ -728,7 +720,7 @@ public PrivateChannel getPrivateChannelById(long id) @Nonnull @Override - public RestAction openPrivateChannelById(long userId) + public CacheRestAction openPrivateChannelById(long userId) { if (selfUser != null && userId == selfUser.getIdLong()) throw new UnsupportedOperationException("Cannot open private channel with yourself!"); diff --git a/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java index 0cc0331ef8..8faf3ad812 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java @@ -1090,14 +1090,14 @@ public Task loadMembers(@Nonnull Consumer callback) } // Helper function for deferred cache access - private Member getMember(long id, boolean update, JDAImpl jda) + private Member getMember(long id, JDAImpl jda) { - if (!update || jda.isIntent(GatewayIntent.GUILD_MEMBERS)) + if (jda.isIntent(GatewayIntent.GUILD_MEMBERS)) { // return member from cache if member tracking is enabled through intents Member member = getMemberById(id); // if the join time is inaccurate we also have to load it through REST to update this information - if (!update || (member != null && member.hasTimeJoined())) + if (member != null && member.hasTimeJoined()) return member; } return null; @@ -1105,15 +1105,14 @@ private Member getMember(long id, boolean update, JDAImpl jda) @Nonnull @Override - public RestAction retrieveMemberById(long id, boolean update) + public CacheRestAction retrieveMemberById(long id) { JDAImpl jda = getJDA(); - if (id == jda.getSelfUser().getIdLong()) - return new CompletedRestAction<>(jda, getSelfMember()); - return new DeferredRestAction<>(jda, Member.class, - () -> getMember(id, update, jda), + () -> getMember(id, jda), () -> { // otherwise we need to update the member with a REST request first to get the nickname/roles + if (id == jda.getSelfUser().getIdLong()) + return new CompletedRestAction<>(jda, getSelfMember()); Route.CompiledRoute route = Route.Guilds.GET_MEMBER.compile(getId(), Long.toUnsignedString(id)); return new RestActionImpl<>(jda, route, (resp, req) -> { MemberImpl member = jda.getEntityBuilder().createMember(this, resp.getObject()); diff --git a/src/main/java/net/dv8tion/jda/internal/entities/SelfUserImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/SelfUserImpl.java index 587334bd73..9d3de493c1 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/SelfUserImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/SelfUserImpl.java @@ -19,7 +19,7 @@ import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.entities.SelfUser; import net.dv8tion.jda.api.managers.AccountManager; -import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.requests.restaction.CacheRestAction; import net.dv8tion.jda.internal.JDAImpl; import net.dv8tion.jda.internal.managers.AccountManagerImpl; @@ -57,7 +57,7 @@ public PrivateChannel getPrivateChannel() @Nonnull @Override - public RestAction openPrivateChannel() + public CacheRestAction openPrivateChannel() { throw new UnsupportedOperationException("You cannot open a PrivateChannel with yourself (SelfUser)"); } diff --git a/src/main/java/net/dv8tion/jda/internal/entities/ThreadChannelImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/ThreadChannelImpl.java index 2d61c74192..06c8de8c04 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/ThreadChannelImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/ThreadChannelImpl.java @@ -20,6 +20,7 @@ import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.managers.channel.concrete.ThreadChannelManager; import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.requests.restaction.CacheRestAction; import net.dv8tion.jda.api.utils.TimeUtil; import net.dv8tion.jda.api.utils.cache.CacheView; import net.dv8tion.jda.api.utils.data.DataArray; @@ -148,16 +149,15 @@ public ThreadMember getThreadMemberById(long id) @Nonnull @Override - public RestAction retrieveThreadMemberById(long id) + public CacheRestAction retrieveThreadMemberById(long id) { JDAImpl jda = (JDAImpl) getJDA(); return new DeferredRestAction<>(jda, ThreadMember.class, () -> getThreadMemberById(id), () -> { Route.CompiledRoute route = Route.Channels.GET_THREAD_MEMBER.compile(getId(), Long.toUnsignedString(id)); - return new RestActionImpl<>(jda, route, (resp, req) -> { - return jda.getEntityBuilder().createThreadMember(getGuild(), this, resp.getObject()); - }); + return new RestActionImpl<>(jda, route, (resp, req) -> + jda.getEntityBuilder().createThreadMember(getGuild(), this, resp.getObject())); }); } diff --git a/src/main/java/net/dv8tion/jda/internal/entities/UserImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/UserImpl.java index b4d04e6280..3ad385dadc 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/UserImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/UserImpl.java @@ -19,7 +19,7 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.requests.RestAction; +import net.dv8tion.jda.api.requests.restaction.CacheRestAction; import net.dv8tion.jda.api.utils.MiscUtil; import net.dv8tion.jda.api.utils.data.DataObject; import net.dv8tion.jda.internal.JDAImpl; @@ -78,7 +78,7 @@ public String getAvatarId() @Nonnull @Override - public RestAction retrieveProfile() + public CacheRestAction retrieveProfile() { return new DeferredRestAction<>(getJDA(), Profile.class, this::getProfile, () -> { Route.CompiledRoute route = Route.Users.GET_USER.compile(getId()); @@ -120,7 +120,7 @@ public boolean hasPrivateChannel() @Nonnull @Override - public RestAction openPrivateChannel() + public CacheRestAction openPrivateChannel() { return new DeferredRestAction<>(getJDA(), PrivateChannel.class, this::getPrivateChannel, () -> { Route.CompiledRoute route = Route.Self.CREATE_PRIVATE_CHANNEL.compile();