Skip to content

Commit

Permalink
Remove outdated todo comments and update outdated logic in thread cha…
Browse files Browse the repository at this point in the history
…nnels (#2581)
  • Loading branch information
MinnDevelopment authored Nov 12, 2023
1 parent 7bdeea8 commit b7937d0
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
*/
public enum ChannelField
{
//TODO-v5: Should these be the REST JSON names (camelCase), the AuditLogKey names (snake_case), or JDA's generic naming (Event.IDENTIFIER)
//TODO-v5: Current using JDA's generic namings

//Generic

/**
Expand Down Expand Up @@ -76,7 +73,6 @@ public enum ChannelField
*/
PARENT("parent", AuditLogKey.CHANNEL_PARENT),

//TODO-v5 if the calculation of IPositionableChannel#getPosition() changes, this may need modification too.
/**
* The position of this channel relative to other channels in the guild.
*
Expand Down Expand Up @@ -162,7 +158,7 @@ public enum ChannelField
* @see AudioChannel#getRegion()
* @see net.dv8tion.jda.api.Region
*/
REGION("region", null), //TODO-v5: JDA needs to add support for channel-specific audit log tracking
REGION("region", null),

/**
* The maximum user count of this channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*/
public interface ICategorizableChannel extends GuildChannel, IPermissionContainer
{
//TODO-v5: Docs
@Override
@Nonnull
ICategorizableChannelManager<?, ?> getManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
*/
public interface IPermissionContainer extends GuildChannel
{
//TODO-v5: Docs
@Override
@Nonnull
IPermissionContainerManager<?, ?> getManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
*/
public interface IPositionableChannel extends GuildChannel
{
//TODO-v5: Docs
@Override
@Nonnull
IPositionableChannelManager<?, ?> getManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ default ThreadMember getOwnerThreadMember()
* </ul>
*
* @throws IllegalStateException
* If this thread is locked or archived.
* If this thread is archived.
*
* @return {@link RestAction}
*/
Expand All @@ -657,16 +657,14 @@ default ThreadMember getOwnerThreadMember()
* </ul>
*
* @throws IllegalStateException
* If this thread is locked or archived.
* If this thread is archived.
*
* @return {@link RestAction}
*/
@Nonnull
@CheckReturnValue
RestAction<Void> leave();

//TODO-v5: re-document this method as permission checks are included in the impl.
//this is probably also affected by private threads that are not invitable
/**
* Adds a member to this thread.
* <br>This will have no effect if the member is already a member of this thread.
Expand Down Expand Up @@ -697,8 +695,14 @@ default ThreadMember getOwnerThreadMember()
* @param id
* The id of the member to add.
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* <ul>
* <li>If this is a {@link #isPublic() private thread} or not {@link #isInvitable()},
* and the bot does not have {@link net.dv8tion.jda.api.Permission#MANAGE_THREADS MANAGE_THREADS} permission and is not the {@link #getOwner()}.</li>
* <li>If the bot does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_SEND_IN_THREADS MESSAGE_SEND_IN_THREADS} permission in the parent channel.</li>
* </ul>
* @throws IllegalStateException
* If this thread is locked or archived.
* If this thread is archived.
*
* @return {@link RestAction}
*/
Expand Down Expand Up @@ -736,6 +740,12 @@ default ThreadMember getOwnerThreadMember()
* @param id
* The id of the member to add.
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* <ul>
* <li>If this is a {@link #isPublic() private thread} or not {@link #isInvitable()},
* and the bot does not have {@link net.dv8tion.jda.api.Permission#MANAGE_THREADS MANAGE_THREADS} permission and is not the {@link #getOwner()}.</li>
* <li>If the bot does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_SEND_IN_THREADS MESSAGE_SEND_IN_THREADS} permission in the parent channel.</li>
* </ul>
* @throws IllegalStateException
* If this thread is locked or archived
* @throws IllegalArgumentException
Expand Down Expand Up @@ -773,6 +783,12 @@ default RestAction<Void> addThreadMemberById(@Nonnull String id)
* @param user
* The {@link User} to add.
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* <ul>
* <li>If this is a {@link #isPublic() private thread} or not {@link #isInvitable()},
* and the bot does not have {@link net.dv8tion.jda.api.Permission#MANAGE_THREADS MANAGE_THREADS} permission and is not the {@link #getOwner()}.</li>
* <li>If the bot does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_SEND_IN_THREADS MESSAGE_SEND_IN_THREADS} permission in the parent channel.</li>
* </ul>
* @throws IllegalStateException
* If this thread is locked or archived.
* @throws IllegalArgumentException
Expand Down Expand Up @@ -811,6 +827,12 @@ default RestAction<Void> addThreadMember(@Nonnull User user)
* @param member
* The {@link Member} to add.
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* <ul>
* <li>If this is a {@link #isPublic() private thread} or not {@link #isInvitable()},
* and the bot does not have {@link net.dv8tion.jda.api.Permission#MANAGE_THREADS MANAGE_THREADS} permission and is not the {@link #getOwner()}.</li>
* <li>If the bot does not have {@link net.dv8tion.jda.api.Permission#MESSAGE_SEND_IN_THREADS MESSAGE_SEND_IN_THREADS} permission in the parent channel.</li>
* </ul>
* @throws IllegalStateException
* If this thread is locked or archived.
* @throws IllegalArgumentException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public interface DefaultGuildChannelUnion extends StandardGuildChannel
@Nonnull
NewsChannel asNewsChannel();

//TODO: add asForumChannel() (I think ForumChannels can be the default?)

/**
* Casts this union to a {@link net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer}.
* This method exists for developer discoverability.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*
* <p>Can be used to retrieve the updated override and old {@link #getOldAllow() allow} and {@link #getOldDeny() deny}.
*/
//TODO-v5: Should this be implementing UpdateEvent?
public class PermissionOverrideUpdateEvent extends GenericPermissionOverrideEvent
{
private final long oldAllow, oldDeny;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.channel.attribute.IPermissionContainer;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.internal.utils.Checks;

Expand Down Expand Up @@ -84,14 +85,13 @@ default PermissionOverrideAction reset()
@Nonnull
PermissionOverrideAction resetDeny();

//TODO-v5: Should probably be IPermissionContainer?
/**
* The {@link GuildChannel} this will be created in
* The {@link IPermissionContainer} this will be created in
*
* @return The channel
*/
@Nonnull
GuildChannel getChannel();
IPermissionContainer getChannel();

/**
* The {@link Role} for this override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* @see net.dv8tion.jda.api.interactions.InteractionHook#editOriginal(String)
* @see net.dv8tion.jda.api.entities.WebhookClient#editMessageById(long, String)
*/
// TODO: WebhookMessage type (no channel/guild attached)
public interface WebhookMessageEditAction<T> extends MessageEditRequest<WebhookMessageEditAction<T>>, AbstractWebhookMessageAction<T, WebhookMessageEditAction<T>>
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public JDA getJDA()
@Override
public Guild getGuild()
{
//TODO is this actually how we want to get the guild? could store it locally in the entity instead if wanted
return thread.getGuild();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public boolean isInvitable()
return invitable;
}

@Nonnull
@Override
public OffsetDateTime getTimeArchiveInfoLastModified()
{
Expand All @@ -272,6 +273,7 @@ public int getSlowmode()
return slowmode;
}

@Nonnull
@Override
public RestAction<Void> join()
{
Expand All @@ -281,6 +283,7 @@ public RestAction<Void> join()
return new RestActionImpl<>(api, route);
}

@Nonnull
@Override
public RestAction<Void> leave()
{
Expand All @@ -290,24 +293,27 @@ public RestAction<Void> leave()
return new RestActionImpl<>(api, route);
}

@Nonnull
@Override
public RestAction<Void> addThreadMemberById(long id)
{
checkUnarchived();
checkInvitable();
checkPermission(Permission.MESSAGE_SEND_IN_THREADS);

Route.CompiledRoute route = Route.Channels.ADD_THREAD_MEMBER.compile(getId(), Long.toUnsignedString(id));
return new RestActionImpl<>(api, route);
}

@Nonnull
@Override
public RestAction<Void> removeThreadMemberById(long id)
{
checkUnarchived();

boolean privateThreadOwner = type == ChannelType.GUILD_PRIVATE_THREAD && ownerId == api.getSelfUser().getIdLong();
if (!privateThreadOwner) {
if (!privateThreadOwner)
checkPermission(Permission.MANAGE_THREADS);
}

Route.CompiledRoute route = Route.Channels.REMOVE_THREAD_MEMBER.compile(getId(), Long.toUnsignedString(id));
return new RestActionImpl<>(api, route);
Expand Down Expand Up @@ -448,4 +454,12 @@ private void checkUnarchived()
if (archived)
throw new IllegalStateException("Cannot modify a ThreadChannel while it is archived!");
}

private void checkInvitable()
{
if (ownerId == api.getSelfUser().getIdLong()) return;

if (!isPublic() && !isInvitable())
checkPermission(Permission.MANAGE_THREADS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ else if (guild == null)

final long channelId = content.getLong("channel_id");

//TODO-v5-unified-channel-cache
MessageChannel channel = getJDA().getChannelById(MessageChannel.class, channelId);

//We don't have the channel cached yet. We chose not to cache this event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ protected Long handleInternally(DataObject content)
if (getJDA().getGuildSetupController().isLocked(guildId))
return guildId;

// TODO: Handle these voice states properly
if (content.isNull("member"))
{
WebSocketClient.LOG.debug("Discarding VOICE_STATE_UPDATE with missing member. JSON: {}", content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,6 @@ public ConnectionRequest removeAudioConnection(long guildId)
{
//This will only be used by GuildDeleteHandler to ensure that
// no further voice state updates are sent for this Guild
//TODO: users may still queue new requests via the old AudioManager, how could we prevent this?
return locked("There was an error cleaning up audio connections for deleted guild", () -> queuedAudioConnections.remove(guildId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.PermissionOverride;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.channel.attribute.IPermissionContainer;
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.requests.Request;
Expand Down Expand Up @@ -135,7 +136,7 @@ public PermissionOverrideAction resetDeny()

@Nonnull
@Override
public GuildChannel getChannel()
public IPermissionContainer getChannel()
{
return channel;
}
Expand Down

0 comments on commit b7937d0

Please sign in to comment.