From b7937d07515c9274a527a5a192a3ed55d77fe892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Spie=C3=9F?= Date: Sun, 12 Nov 2023 18:56:59 +0100 Subject: [PATCH] Remove outdated todo comments and update outdated logic in thread channels (#2581) --- .../api/entities/channel/ChannelField.java | 6 +--- .../attribute/ICategorizableChannel.java | 1 - .../attribute/IPermissionContainer.java | 1 - .../attribute/IPositionableChannel.java | 1 - .../channel/concrete/ThreadChannel.java | 32 ++++++++++++++++--- .../unions/DefaultGuildChannelUnion.java | 2 -- .../PermissionOverrideUpdateEvent.java | 1 - .../restaction/PermissionOverrideAction.java | 6 ++-- .../restaction/WebhookMessageEditAction.java | 1 - .../internal/entities/ThreadMemberImpl.java | 1 - .../channel/concrete/ThreadChannelImpl.java | 18 +++++++++-- .../internal/handle/TypingStartHandler.java | 1 - .../handle/VoiceStateUpdateHandler.java | 1 - .../internal/requests/WebSocketClient.java | 1 - .../PermissionOverrideActionImpl.java | 3 +- 15 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/ChannelField.java b/src/main/java/net/dv8tion/jda/api/entities/channel/ChannelField.java index 9b9ee49afa..681c1d15a0 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/ChannelField.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/ChannelField.java @@ -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 /** @@ -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. * @@ -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. diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/ICategorizableChannel.java b/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/ICategorizableChannel.java index d10fc50645..80e42151b6 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/ICategorizableChannel.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/ICategorizableChannel.java @@ -33,7 +33,6 @@ */ public interface ICategorizableChannel extends GuildChannel, IPermissionContainer { - //TODO-v5: Docs @Override @Nonnull ICategorizableChannelManager getManager(); diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IPermissionContainer.java b/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IPermissionContainer.java index c7427c360a..f0c0920838 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IPermissionContainer.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IPermissionContainer.java @@ -38,7 +38,6 @@ */ public interface IPermissionContainer extends GuildChannel { - //TODO-v5: Docs @Override @Nonnull IPermissionContainerManager getManager(); diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IPositionableChannel.java b/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IPositionableChannel.java index cbd92703f4..03d50a898b 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IPositionableChannel.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/attribute/IPositionableChannel.java @@ -30,7 +30,6 @@ */ public interface IPositionableChannel extends GuildChannel { - //TODO-v5: Docs @Override @Nonnull IPositionableChannelManager getManager(); diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/ThreadChannel.java b/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/ThreadChannel.java index a9f68737e7..0fd29a73d5 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/ThreadChannel.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/concrete/ThreadChannel.java @@ -634,7 +634,7 @@ default ThreadMember getOwnerThreadMember() * * * @throws IllegalStateException - * If this thread is locked or archived. + * If this thread is archived. * * @return {@link RestAction} */ @@ -657,7 +657,7 @@ default ThreadMember getOwnerThreadMember() * * * @throws IllegalStateException - * If this thread is locked or archived. + * If this thread is archived. * * @return {@link RestAction} */ @@ -665,8 +665,6 @@ default ThreadMember getOwnerThreadMember() @CheckReturnValue RestAction 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. *
This will have no effect if the member is already a member of this thread. @@ -697,8 +695,14 @@ default ThreadMember getOwnerThreadMember() * @param id * The id of the member to add. * + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException + * * @throws IllegalStateException - * If this thread is locked or archived. + * If this thread is archived. * * @return {@link RestAction} */ @@ -736,6 +740,12 @@ default ThreadMember getOwnerThreadMember() * @param id * The id of the member to add. * + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException + * * @throws IllegalStateException * If this thread is locked or archived * @throws IllegalArgumentException @@ -773,6 +783,12 @@ default RestAction addThreadMemberById(@Nonnull String id) * @param user * The {@link User} to add. * + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException + *
    + *
  • 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()}.
  • + *
  • 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.
  • + *
* @throws IllegalStateException * If this thread is locked or archived. * @throws IllegalArgumentException @@ -811,6 +827,12 @@ default RestAction addThreadMember(@Nonnull User user) * @param member * The {@link Member} to add. * + * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException + *
    + *
  • 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()}.
  • + *
  • 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.
  • + *
* @throws IllegalStateException * If this thread is locked or archived. * @throws IllegalArgumentException diff --git a/src/main/java/net/dv8tion/jda/api/entities/channel/unions/DefaultGuildChannelUnion.java b/src/main/java/net/dv8tion/jda/api/entities/channel/unions/DefaultGuildChannelUnion.java index 34ab88534b..dddb1fb4ab 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/channel/unions/DefaultGuildChannelUnion.java +++ b/src/main/java/net/dv8tion/jda/api/entities/channel/unions/DefaultGuildChannelUnion.java @@ -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. diff --git a/src/main/java/net/dv8tion/jda/api/events/guild/override/PermissionOverrideUpdateEvent.java b/src/main/java/net/dv8tion/jda/api/events/guild/override/PermissionOverrideUpdateEvent.java index 22f0b8652f..ea9aac56f4 100644 --- a/src/main/java/net/dv8tion/jda/api/events/guild/override/PermissionOverrideUpdateEvent.java +++ b/src/main/java/net/dv8tion/jda/api/events/guild/override/PermissionOverrideUpdateEvent.java @@ -29,7 +29,6 @@ * *

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; diff --git a/src/main/java/net/dv8tion/jda/api/requests/restaction/PermissionOverrideAction.java b/src/main/java/net/dv8tion/jda/api/requests/restaction/PermissionOverrideAction.java index b78adec0de..6ce8fc31f8 100644 --- a/src/main/java/net/dv8tion/jda/api/requests/restaction/PermissionOverrideAction.java +++ b/src/main/java/net/dv8tion/jda/api/requests/restaction/PermissionOverrideAction.java @@ -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; @@ -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 diff --git a/src/main/java/net/dv8tion/jda/api/requests/restaction/WebhookMessageEditAction.java b/src/main/java/net/dv8tion/jda/api/requests/restaction/WebhookMessageEditAction.java index d4ce63d169..2ef3a9f91d 100644 --- a/src/main/java/net/dv8tion/jda/api/requests/restaction/WebhookMessageEditAction.java +++ b/src/main/java/net/dv8tion/jda/api/requests/restaction/WebhookMessageEditAction.java @@ -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 extends MessageEditRequest>, AbstractWebhookMessageAction> { } diff --git a/src/main/java/net/dv8tion/jda/internal/entities/ThreadMemberImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/ThreadMemberImpl.java index 40709fc47d..c11d0e0bf3 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/ThreadMemberImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/ThreadMemberImpl.java @@ -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(); } diff --git a/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/ThreadChannelImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/ThreadChannelImpl.java index f01c5485c4..e8f21d8819 100644 --- a/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/ThreadChannelImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/entities/channel/concrete/ThreadChannelImpl.java @@ -246,6 +246,7 @@ public boolean isInvitable() return invitable; } + @Nonnull @Override public OffsetDateTime getTimeArchiveInfoLastModified() { @@ -272,6 +273,7 @@ public int getSlowmode() return slowmode; } + @Nonnull @Override public RestAction join() { @@ -281,6 +283,7 @@ public RestAction join() return new RestActionImpl<>(api, route); } + @Nonnull @Override public RestAction leave() { @@ -290,24 +293,27 @@ public RestAction leave() return new RestActionImpl<>(api, route); } + @Nonnull @Override public RestAction 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 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); @@ -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); + } } diff --git a/src/main/java/net/dv8tion/jda/internal/handle/TypingStartHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/TypingStartHandler.java index 23efe01803..462734d8a8 100644 --- a/src/main/java/net/dv8tion/jda/internal/handle/TypingStartHandler.java +++ b/src/main/java/net/dv8tion/jda/internal/handle/TypingStartHandler.java @@ -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 diff --git a/src/main/java/net/dv8tion/jda/internal/handle/VoiceStateUpdateHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/VoiceStateUpdateHandler.java index 635a7295f9..a5b114bc0a 100644 --- a/src/main/java/net/dv8tion/jda/internal/handle/VoiceStateUpdateHandler.java +++ b/src/main/java/net/dv8tion/jda/internal/handle/VoiceStateUpdateHandler.java @@ -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); diff --git a/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java b/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java index 7f96b98eb9..aa02b8e52e 100644 --- a/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java +++ b/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java @@ -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)); } diff --git a/src/main/java/net/dv8tion/jda/internal/requests/restaction/PermissionOverrideActionImpl.java b/src/main/java/net/dv8tion/jda/internal/requests/restaction/PermissionOverrideActionImpl.java index 91f885b0d6..75a84cfe0a 100644 --- a/src/main/java/net/dv8tion/jda/internal/requests/restaction/PermissionOverrideActionImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/requests/restaction/PermissionOverrideActionImpl.java @@ -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; @@ -135,7 +136,7 @@ public PermissionOverrideAction resetDeny() @Nonnull @Override - public GuildChannel getChannel() + public IPermissionContainer getChannel() { return channel; }