Skip to content

Commit

Permalink
Implement retrieveThreadMember (#1919)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Spieß <business@minn.dev>
  • Loading branch information
Tais993 and MinnDevelopment committed Dec 24, 2021
1 parent 11bbb83 commit 1e306fb
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 3 deletions.
82 changes: 82 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java
Expand Up @@ -101,6 +101,88 @@ default ThreadMember getThreadMemberById(String id)
@Nullable
ThreadMember getThreadMemberById(long id);

/**
* Load the thread-member for the specified user.
* <br>If the thread-member is already loaded it, will be retrieved from {@link #getThreadMemberById(long)}
* and immediately provided if the thread-member information is consistent. If the bot hasn't joined the thread,
* {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} is required to keep the cache updated.
*
* @param member
* The member to load the thread-member from
*
* @throws IllegalArgumentException
* If provided with null
*
* @return {@link RestAction} - Type: {@link ThreadMember}
*/
@Nonnull
@CheckReturnValue
default RestAction<ThreadMember> retrieveThreadMember(@Nonnull Member member)
{
Checks.notNull(member, "Member");
return retrieveThreadMemberById(member.getIdLong());
}

/**
* Load the thread-member for the specified user.
* <br>If the thread-member is already loaded, it will be retrieved from {@link #getThreadMemberById(long)}
* and immediately provided if the thread-member information is consistent. If the bot hasn't joined the thread,
* {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} is required to keep the cache updated.
*
* @param user
* The user to load the thread-member from
*
* @throws IllegalArgumentException
* If provided with null
*
* @return {@link RestAction} - Type: {@link ThreadMember}
*/
@Nonnull
@CheckReturnValue
default RestAction<ThreadMember> retrieveThreadMember(@Nonnull User user)
{
Checks.notNull(user, "User");
return retrieveThreadMemberById(user.getIdLong());
}

/**
* Load the thread-member for the user with the specified id.
* <br>If the thread-member is already loaded, it will be retrieved from {@link #getThreadMemberById(long)}
* and immediately provided if the thread-member information is consistent. If the bot hasn't joined the thread,
* {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} is required to keep the cache updated.
*
* @param id
* The user id to load the thread-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 ThreadMember}
*/
@Nonnull
@CheckReturnValue
default RestAction<ThreadMember> retrieveThreadMemberById(@Nonnull String id)
{
return retrieveThreadMemberById(MiscUtil.parseSnowflake(id));
}

/**
* Load the thread-member for the user with the specified id.
* <br>If the thread-member is already loaded, it will be retrieved from {@link #getThreadMemberById(long)}
* and immediately provided if the thread-member information is consistent. If the bot hasn't joined the thread,
* {@link net.dv8tion.jda.api.requests.GatewayIntent#GUILD_MEMBERS GatewayIntent.GUILD_MEMBERS} is required to keep the cache updated.
*
* @param id
* The user id to load the thread-member from
*
* @return {@link RestAction} - Type: {@link ThreadMember}
*/
@Nonnull
@CheckReturnValue
RestAction<ThreadMember> retrieveThreadMemberById(long id);

@CheckReturnValue
RestAction<List<ThreadMember>> retrieveThreadMembers();

Expand Down
Expand Up @@ -23,22 +23,24 @@
import net.dv8tion.jda.api.utils.cache.CacheView;
import net.dv8tion.jda.api.utils.data.DataArray;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.entities.mixin.channel.middleman.GuildMessageChannelMixin;
import net.dv8tion.jda.internal.managers.channel.concrete.ThreadChannelManagerImpl;
import net.dv8tion.jda.internal.requests.DeferredRestAction;
import net.dv8tion.jda.internal.requests.RestActionImpl;
import net.dv8tion.jda.internal.requests.Route;
import net.dv8tion.jda.internal.utils.Checks;
import net.dv8tion.jda.internal.utils.Helpers;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.OffsetDateTime;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class ThreadChannelImpl extends AbstractGuildChannelImpl<ThreadChannelImpl> implements
ThreadChannel,
public class ThreadChannelImpl extends AbstractGuildChannelImpl<ThreadChannelImpl> implements
ThreadChannel,
GuildMessageChannelMixin<ThreadChannelImpl>
{
private final ChannelType type;
Expand Down Expand Up @@ -135,6 +137,21 @@ public ThreadMember getThreadMemberById(long id)
return threadMembers.get(id);
}

@Nonnull
@Override
public RestAction<ThreadMember> 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());
});
});
}

@Override
public RestAction<List<ThreadMember>> retrieveThreadMembers()
{
Expand Down

0 comments on commit 1e306fb

Please sign in to comment.