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
Introduce Channel Unions #2138
Merged
Merged
Introduce Channel Unions #2138
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DV8FromTheWorld
added
type: breaking
contains a backwards incompatible change
status: documentation needed
lacks documentation, either partially or completely
priority: high
type: feature
type: enhancement
and removed
type: feature
labels
May 22, 2022
If we find that we need this union in the future we can re-add it, but currently nothing is using it.
DV8FromTheWorld
commented
May 22, 2022
src/main/java/net/dv8tion/jda/api/entities/IWebhookContainer.java
Outdated
Show resolved
Hide resolved
DV8FromTheWorld
removed
the
status: documentation needed
lacks documentation, either partially or completely
label
May 22, 2022
…feature/channel-unions # Conflicts: # src/main/java/net/dv8tion/jda/api/entities/Guild.java # src/main/java/net/dv8tion/jda/api/entities/Message.java # src/main/java/net/dv8tion/jda/api/requests/restaction/MessageAction.java # src/main/java/net/dv8tion/jda/internal/entities/AbstractMessage.java # src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java # src/main/java/net/dv8tion/jda/internal/entities/ReceivedMessage.java # src/main/java/net/dv8tion/jda/internal/entities/mixin/channel/middleman/GuildMessageChannelMixin.java # src/main/java/net/dv8tion/jda/internal/requests/restaction/MessageActionImpl.java
…eWorld/JDA into feature/channel-unions
src/main/java/net/dv8tion/jda/api/entities/channel/unions/DefaultGuildChannelUnion.java
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/entities/channel/unions/DefaultGuildChannelUnion.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/entities/channel/unions/DefaultGuildChannelUnion.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/entities/channel/unions/IWebhookContainerUnion.java
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/entities/channel/unions/MessageChannelUnion.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/interactions/commands/OptionMapping.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/internal/entities/AbstractChannelImpl.java
Outdated
Show resolved
Hide resolved
This PR should also move the channel interfaces into a dedicated package |
…feature/channel-unions # Conflicts: # src/main/java/net/dv8tion/jda/api/entities/Guild.java # src/main/java/net/dv8tion/jda/api/entities/Member.java # src/main/java/net/dv8tion/jda/api/entities/Message.java # src/main/java/net/dv8tion/jda/api/entities/MessageReaction.java # src/main/java/net/dv8tion/jda/internal/entities/AbstractMessage.java # src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java # src/main/java/net/dv8tion/jda/internal/entities/MemberImpl.java # src/main/java/net/dv8tion/jda/internal/entities/ReceivedMessage.java # src/main/java/net/dv8tion/jda/internal/entities/mixin/channel/middleman/GuildMessageChannelMixin.java # src/main/java/net/dv8tion/jda/internal/entities/mixin/channel/middleman/MessageChannelMixin.java
src/main/java/net/dv8tion/jda/api/interactions/Interaction.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/internal/entities/WebhookImpl.java
Outdated
Show resolved
Hide resolved
src/main/java/net/dv8tion/jda/api/events/message/GenericMessageEvent.java
Show resolved
Hide resolved
6 tasks
This PR should also address GenericChannelEvent |
…n system Part of this change involved changed MessageReaction#getGuildChannel to throw instead of returning null when not in a guild context.
PR now addresses GenericChannelEvent |
src/main/java/net/dv8tion/jda/api/entities/MessageReaction.java
Outdated
Show resolved
Hide resolved
MinnDevelopment
approved these changes
Jul 3, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After addressing the MessageReaction#getGuild
and the javadoc error, this should be good to go.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Etiquette
Changes
Closes Issue: NaN
Description
The goal of this PR is to introduce Unions to JDA for channel types while also reworking the type hierarchy slightly to make way for ForumChannels and Messages in VoiceChannels (aka TextInVoice (TiV))
This PR changes the return types of a lot of method (basically all of them) that are the type
getX : XChannel
(e.g:Message#getChannel() : MessageChannel
) to instead return union types (MessageChannelUnion
in this case). Also, before you panic, anywhere that changed from XChannel -> XChannelUnion is completely compatible with 0 changes to existing bot/developer code because unions are extensions of the interface their representing.Additionally, a variety of channel getters have been changed to return more limited channel classes so that they can properly represent the channel types returned. For example, the
Webhook#getChannel
used to returnBaseGuildMessageChannel
but now instead returnsIWebhookContainerUnion
. Read on for more info!Unions
In JDA, a Union will represent a type that has getters on it to provide a signal to the developer of what types are available in this type. Technically this information is typically available via documentation, but we've found that this is also a great way to introduce additional discoverability.
These getters are in the format
asX
likeasTextChannel() : TextChannel
. The are effectively just casts, but they provide a method of introducing the available interfaces and types that are represented by the union. They also provide a way to introduce developers to "in-between" or "bridge" interfaces that may be useful likeStandardGuildChannel
or direct them to known useful casts like toIThreadContainer
.For example, the
GuildMessageChannelUnion
. TheGuildMessageChannelUnion
interface extends theGuildMessageChannel
interface and differs only by providing the getters that can implementGuildMessageChannel
:asTextChannel() : TextChannel
asNewsChannel() : NewsChannel
asThreadChannel() : ThreadChannel
asStandardGuildChannel() : StandardGuildChannel
asStandardGuildMessageChannel() : StandardGuildMessageChannel
Clean Interfaces
Another thing to note is that Unions are not directly included in the normal type hierarchy, so their
asX
getters are not present on the end concrete interface. For example, when looking at aTextChannel tchan = jda.getTextChannelById("...")
thetchan
variable will not have theasNewsChannel
(nor any otherasXChannel
getter) on it even thoughTextChannel
implementsGuildMessageChannel
. This is because the type hierarchy forTextChannel
does not contain theGuildMessageChannelUnion
interface, only theGuildMessageChannel
interface. This means devs aren't going to have weirdasX
getters when they aren't needed, and this is an expectation we place on all unions going forward.Unions are NOT wrapper objects
(This is mostly for the curious)
While the concrete type interfaces like
TextChannel
do not inherit from the Union classes, theirXImpl
(likeTextChannelImpl
) do implement them.The advantage of this is 2 fold. Like mentioned before, the interfaces presented to developers are clean of these
asX
getters when they aren't pertinent anymore (after you've left the union type for a concrete type) however since the Impl implements it it means that when a method calls for a union (likeGuildChannelMessageUnion
) and we have the non union type (likeGuildChannelMessage
) we can confidently just cast from the normal type to the union type because we know the underlying Impl that represents that channel supports the union.This is nice because it means we don't need special union wrappers to wrap objects to be returned by
asX
. The object itself is the union.For the really curious
Given the above, here is an example
TextChannel < StandardGuildMessageChannel < StandardGuildChannel + GuildMessageChannel + ...
TextChannelImpl < StandardGuildMessageChannelImpl < StandardGuildChannelImpl + GuildChannelMessageUnion + ...
Note how the impl uses the union when building up
StandardGuildMessageChannelImpl
but the interface usesGuildMessageChannel
when building upStandardGuildMessageChannel
.(technically the impl uses
GuildMessageChannelMixin
which includes the union, but I digress)Removed Types
BaseGuildMessageChannel
The BGMC served as a great accumulator of all of the "attribute interfaces" (the IXChannel / IXContainer interfaces, ex:
IThreadContainer
) and acted as a base betweenTextChannel
andNewsChannel
. While this is really useful it cannot be reused for other messaging situations likeTiV
(because TiV doesn't support threads!) and we were returning BGMC from some methods that no longer can fully model the functionalities promised by BGMC likeGuild#getDefaultChannel
asForumChannels
can be a default channel in the future and they don't supportMessageChannel
!As such, the functionality present in this type technically lives on in a form in
StandardGuildMessageChannel
, but it would be wrong to say it is simply renamed. A large amount of the "base" functionality present in this interface has now been spread out acrossStandardGuildChannel
andStandardGuildMessageChannel
. Additionally, most (if not all) of thegetX : BGMC
getters have been changed to return a super type with a more limited set of functionalities compared to the previous usages of BGMC due needing to support future Discord changes. Going back to ourGuild#getDefaultChannel
it now returnsDefaultGuildChannelUnion
to better represent the functionalities expected by a default channel.New Types
Channel Types
IWebhookContainer
Represents any channel that can add/edit/remove webhooks
StandardGuildChannel
Represents any of the "normal" Guild channels. These are the channels that are in the sidebar and have the "standard" functionalities expected by channels.
StandardGuildMessageChannel
Represents any of the "normal" message channels in a Guild. This is the bridge interface between
TextChannels
andNewsChannels
and generally supersedes the responsibility thatBaseGuildMessageChannel
had previously.Union Types
GuildChannelUnion
Represents the union of all
GuildChannel
channels.MessageChannelUnion
Represents the union of all
MessageChannel
channels.GuildMessageChannelUnion
Represents the union of all
GuildMessageChannel
channels.IWebhookContainerUnion
Represents the union of all
IWebhookContainer
channels.IThreadContainerUnion
Represents the union of all
IThreadContainer
channels.DefaultGuildChannelUnion
This is a specialized Union as it doesn't follow the expected pattern defined by the "normal" unions above. This Union extends
StandardGuildChannel
just likeStandardGuildChannelUnion
but it is specialized to only haveasXChannel
methods for the channels that are actually viable for theGuild#getDefaultChannel
andMember#getDefaultChannel
methods. This is in contrast to theStandardGuildChannelUnion
which has anasXChannel
on it for every channel type that implementsStandardGuildChannel
In the future we may have more specialized unions that follow this pattern, but for now this is the only specialized union.
Examples