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

Dont override latest message id on deletion event #2013

Merged
merged 4 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 4 additions & 29 deletions src/main/java/net/dv8tion/jda/api/entities/MessageChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,14 @@ public interface MessageChannel extends Channel, Formattable
/**
* The id for the most recent message sent
* in this current MessageChannel.
* <br>This should only be used if {@link #hasLatestMessage()} returns {@code true}!
*
* <p>This value is updated on each {@link net.dv8tion.jda.api.events.message.MessageReceivedEvent MessageReceivedEvent}
* and <u><b>will be reset to {@code null} if the message associated with this ID gets deleted</b></u>
*
* @throws java.lang.IllegalStateException
* If no message id is available
* and <u><b>the value might point to an already deleted message since the ID is not cleared when the message is deleted,
* so calling {@link #retrieveMessageById(long)} with this id can throw {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}</b></u>
DV8FromTheWorld marked this conversation as resolved.
Show resolved Hide resolved
*
* @return The most recent message's id
*/
@Nonnull
//TODO-v5: Revisit this. Surely this should be Nullable instead of throw an exception...
default String getLatestMessageId()
{
return Long.toUnsignedString(getLatestMessageIdLong());
Expand All @@ -106,36 +102,15 @@ default String getLatestMessageId()
/**
* The id for the most recent message sent
* in this current MessageChannel.
* <br>This should only be used if {@link #hasLatestMessage()} returns {@code true}!
*
* <p>This value is updated on each {@link net.dv8tion.jda.api.events.message.MessageReceivedEvent MessageReceivedEvent}
* and <u><b>will be reset to {@code null} if the message associated with this ID gets deleted</b></u>
*
* @throws java.lang.IllegalStateException
* If no message id is available
* and <u><b>the value might point to an already deleted message since the value is not cleared when the message is deleted,
* so calling {@link #retrieveMessageById(long)} with this id can throw {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE}</b></u>
DV8FromTheWorld marked this conversation as resolved.
Show resolved Hide resolved
*
* @return The most recent message's id
*/
long getLatestMessageIdLong();

/**
* Whether this MessageChannel contains a tracked most recent
* message or not.
*
* <p>This does not directly mean that {@link #getHistory()} will be unable to retrieve past messages,
* it merely means that the latest message is untracked by our internal cache meaning that
* if this returns {@code false} the {@link #getLatestMessageId()}
* method will throw an {@link java.util.NoSuchElementException NoSuchElementException}
*
* @return True, if a latest message id is available for retrieval by {@link #getLatestMessageId()}
*
* @see #getLatestMessageId()
*/
default boolean hasLatestMessage()
{
return getLatestMessageIdLong() != 0;
}

/**
* Whether the currently logged in user can send messages in this channel or not.
* <br>For {@link GuildMessageChannel} this method checks for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ protected Long handleInternally(DataObject content)
return null;
}

// Reset the latest message id as it was deleted.
if (channel.hasLatestMessage() & messageId == channel.getLatestMessageIdLong())
{
((MessageChannelMixin<?>) channel).setLatestMessageIdLong(0);
}

if (channel.getType().isThread())
{
ThreadChannelImpl gThread = (ThreadChannelImpl) channel;
Expand Down