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

Use deep copy for layout components when applying message data #2236

Merged
merged 8 commits into from Nov 8, 2022
Expand Up @@ -269,6 +269,13 @@ public ActionRow asEnabled()
return withDisabled(false);
}

@Nonnull
@Override
public LayoutComponent createCopy()
freya022 marked this conversation as resolved.
Show resolved Hide resolved
{
return ActionRow.of(components);
}

@Nonnull
@Override
public Component.Type getType()
Expand Down
Expand Up @@ -190,6 +190,15 @@ default boolean isValid()
return true;
}

/**
* Creates a copy of this {@link LayoutComponent}.
* <br>This does not create copies of the contained components.
*
* @return A copy of this {@link LayoutComponent}
*/
@Nonnull
LayoutComponent createCopy();

/**
* Find and replace a component in this layout.
* <br>This will locate and replace the existing component with the specified ID. If you provide null it will be removed instead.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/dv8tion/jda/api/utils/FileUpload.java
Expand Up @@ -301,6 +301,16 @@ public String getName()
return name;
}

/**
* The description for the file.
*
* @return The description
*/
public String getDescription()
freya022 marked this conversation as resolved.
Show resolved Hide resolved
{
return description;
}

/**
* The {@link InputStream} representing the data to upload as a file.
*
Expand Down
Expand Up @@ -313,6 +313,8 @@ default R addFiles(@Nonnull FileUpload... files)
/**
* Applies the provided {@link MessageCreateData} to this request.
*
* <p>Note that <b>files will not be copied</b>.
*
* @param data
* The message create data to apply
*
Expand All @@ -325,15 +327,18 @@ default R addFiles(@Nonnull FileUpload... files)
default R applyData(@Nonnull MessageCreateData data)
{
Checks.notNull(data, "MessageCreateData");

final List<LayoutComponent> layoutComponents = data.getComponents().stream()
.map(LayoutComponent::createCopy)
.collect(Collectors.toList());
return setContent(data.getContent())
.setAllowedMentions(data.getAllowedMentions())
.mentionUsers(data.getMentionedUsers())
.mentionRoles(data.getMentionedRoles())
.mentionRepliedUser(data.isMentionRepliedUser())
.setEmbeds(data.getEmbeds())
.setTTS(data.isTTS())
.setComponents(data.getComponents())
.setFiles(data.getFiles());
freya022 marked this conversation as resolved.
Show resolved Hide resolved
.setComponents(layoutComponents);
}

@Nonnull
Expand Down