Skip to content

Commit

Permalink
Dont override latest message id on deletion event (#2013)
Browse files Browse the repository at this point in the history
Co-authored-by: Austin Keener <keeneraustin@yahoo.com>
  • Loading branch information
ishwi and DV8FromTheWorld committed Feb 19, 2022
1 parent e328d17 commit bcb71aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 35 deletions.
33 changes: 4 additions & 29 deletions src/main/java/net/dv8tion/jda/api/entities/MessageChannel.java
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 result in an {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE} error</b></u>
*
* @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 result in an {@link net.dv8tion.jda.api.requests.ErrorResponse#UNKNOWN_MESSAGE UNKNOWN_MESSAGE} error</b></u>
*
* @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
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

0 comments on commit bcb71aa

Please sign in to comment.