Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement retrieveThreadMember #1919

Merged
merged 8 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/ThreadChannel.java
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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