Skip to content

Commit

Permalink
Fix message updater
Browse files Browse the repository at this point in the history
remove random copy call


add createUpdater() to Message
  • Loading branch information
bassner committed Aug 8, 2021
1 parent 064e5de commit 386b25b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,16 @@ default CompletableFuture<Message> edit(String content, EmbedBuilder embed) {
return Message.edit(getApi(), getChannel().getId(), getId(), content, true, embed, true);
}

/**
* Creates a new {@link MessageUpdater} for this message that can be used similarly to a builder to edit this
* message.
*
* @return the new message updater
*/
default MessageUpdater createUpdater() {
return new MessageUpdater(this);
}

/**
* Removes the content of the message.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class MessageUpdater extends MessageBuilderBase<MessageUpdater> {
*/
public MessageUpdater(Message m) {
super(MessageUpdater.class);
delegate.copy(m);
this.message = m;
}

Expand All @@ -27,7 +26,7 @@ public MessageUpdater(Message m) {
* @return The edited message.
*/
public CompletableFuture<Message> applyChanges() {
return delegate.edit(message, true);
return delegate.edit(message, false);
}

/**
Expand All @@ -37,6 +36,6 @@ public CompletableFuture<Message> applyChanges() {
* @return The edited message.
*/
public CompletableFuture<Message> replaceMessage() {
return delegate.edit(message, false);
return delegate.edit(message, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,11 @@ public interface MessageBuilderBaseDelegate {
* Edits the message.
*
* @param message The message to edit.
* @param onlyChangedFields True if only changed fields should be updated
* @param allFields True if all fields should be included in the patch request, even if not changed; False if
* only changed fields should be patched
* @return The edited message.
*/
CompletableFuture<Message> edit(Message message, boolean onlyChangedFields);
CompletableFuture<Message> edit(Message message, boolean allFields);

/**
* Sends the message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,8 @@ private CompletableFuture<Message> executeRequestWithoutAttachments(TextChannel
ObjectNode body,
RestRequest<Message> request) {
request.setBody(body);
return request.execute(result -> ((DiscordApiImpl) channel.getApi())
.getOrCreateMessage(channel, result.getJsonBody()));
return request.execute(result -> new MessageImpl((DiscordApiImpl) channel.getApi(), channel,
result.getJsonBody()));
}

private void prepareAllowedMentions(ObjectNode body) {
Expand Down

0 comments on commit 386b25b

Please sign in to comment.