Skip to content

Commit

Permalink
Fix handling of thread update for unknown parent (#2494)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment authored Jul 3, 2023
1 parent d2ee6ae commit ab3546e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected Long handleInternally(DataObject content)
if (!EntityBuilder.MISSING_CHANNEL.equals(ex.getMessage()))
throw ex;

long parentId = content.getUnsignedLong("parent_id");
long parentId = content.getUnsignedLong("parent_id", 0L);
EventCache.LOG.debug("Caching THREAD_CREATE_EVENT for channel with uncached parent. Parent ID: {}", parentId);
api.getEventCache().cache(EventCache.Type.CHANNEL, parentId, responseNumber, allContent, this::handle);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.dv8tion.jda.api.utils.data.DataArray;
import net.dv8tion.jda.api.utils.data.DataObject;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.entities.EntityBuilder;
import net.dv8tion.jda.internal.entities.channel.concrete.ThreadChannelImpl;
import net.dv8tion.jda.internal.utils.Helpers;
import net.dv8tion.jda.internal.utils.cache.SnowflakeCacheViewImpl;
Expand Down Expand Up @@ -59,11 +60,26 @@ protected Long handleInternally(DataObject content)
//Technically, when the ThreadChannel is unarchived the archive_timestamp (getTimeArchiveInfoLastModified) changes
// as well, but we don't have the original value because we didn't have the thread in memory, so we can't
// provide an entirely accurate ChannelUpdateArchiveTimestampEvent. Not sure how much that'll matter.
thread = (ThreadChannelImpl) api.getEntityBuilder().createThreadChannel(content, guildId);
api.handleEvent(
new ChannelUpdateArchivedEvent(
api, responseNumber,
thread, true, false));
try
{
thread = (ThreadChannelImpl) api.getEntityBuilder().createThreadChannel(content, guildId);
api.handleEvent(
new ChannelUpdateArchivedEvent(
api, responseNumber,
thread, true, false));
}
catch (IllegalArgumentException ex)
{
if (EntityBuilder.MISSING_CHANNEL.equals(ex.getMessage()))
{
long parentId = content.getUnsignedLong("parent_id", 0L);
EventCache.LOG.debug("Caching THREAD_UPDATE for a thread with uncached parent. Parent ID: {} JSON: {}", parentId, content);
api.getEventCache().cache(EventCache.Type.CHANNEL, parentId, responseNumber, allContent, this::handle);
return null;
}

throw ex;
}

return null;
}
Expand All @@ -88,7 +104,6 @@ protected Long handleInternally(DataObject content)
final int oldFlags = thread.getRawFlags();


//TODO should these be Thread specific events?
if (!Objects.equals(oldName, name))
{
thread.setName(name);
Expand Down

0 comments on commit ab3546e

Please sign in to comment.