diff --git a/src/main/java/net/dv8tion/jda/internal/handle/ChannelUpdateHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/ChannelUpdateHandler.java index 842cc20218..89be728fba 100644 --- a/src/main/java/net/dv8tion/jda/internal/handle/ChannelUpdateHandler.java +++ b/src/main/java/net/dv8tion/jda/internal/handle/ChannelUpdateHandler.java @@ -25,6 +25,7 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.IPermissionHolder; import net.dv8tion.jda.api.entities.PermissionOverride; +import net.dv8tion.jda.api.entities.channel.Channel; import net.dv8tion.jda.api.entities.channel.ChannelFlag; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.entities.channel.attribute.IThreadContainer; @@ -53,6 +54,7 @@ import net.dv8tion.jda.internal.entities.channel.mixin.middleman.AudioChannelMixin; import net.dv8tion.jda.internal.requests.WebSocketClient; import net.dv8tion.jda.internal.utils.UnlockHook; +import net.dv8tion.jda.internal.utils.cache.ChannelCacheViewImpl; import net.dv8tion.jda.internal.utils.cache.SnowflakeCacheViewImpl; import net.dv8tion.jda.internal.utils.cache.SortedSnowflakeCacheViewImpl; @@ -220,7 +222,7 @@ private AbstractGuildChannelImpl handleChannelTypeChange(AbstractGuildChannel { //This assumes that if we're moving to a TextChannel that we're transitioning from a NewsChannel NewsChannel newsChannel = (NewsChannel) channel; - getJDA().getNewsChannelView().remove(newsChannel.getIdLong()); + getJDA().getChannelsView().remove(ChannelType.NEWS, newsChannel.getIdLong()); guild.getNewsChannelView().remove(newsChannel.getIdLong()); TextChannelImpl textChannel = (TextChannelImpl) builder.createTextChannel(guild, content, guild.getIdLong()); @@ -240,7 +242,7 @@ private AbstractGuildChannelImpl handleChannelTypeChange(AbstractGuildChannel { //This assumes that if we're moving to a NewsChannel that we're transitioning from a TextChannel TextChannel textChannel = (TextChannel) channel; - getJDA().getTextChannelsView().remove(textChannel.getIdLong()); + getJDA().getChannelsView().remove(ChannelType.TEXT, textChannel.getIdLong()); guild.getTextChannelsView().remove(textChannel.getIdLong()); NewsChannelImpl newsChannel = (NewsChannelImpl) builder.createNewsChannel(guild, content, guild.getIdLong()); @@ -367,16 +369,15 @@ private void handleHideChildThreads(IThreadContainer channel) for (ThreadChannel thread : threads) { GuildImpl guild = (GuildImpl) channel.getGuild(); - SnowflakeCacheViewImpl - guildThreadView = guild.getThreadChannelsView(), - threadView = getJDA().getThreadChannelsView(); + SnowflakeCacheViewImpl guildThreadView = guild.getThreadChannelsView(); + ChannelCacheViewImpl threadView = getJDA().getChannelsView(); try ( UnlockHook vlock = guildThreadView.writeLock(); UnlockHook jlock = threadView.writeLock()) { //TODO-threads: When we figure out how member chunking is going to work for thread related members // we may need to revisit this to ensure they kicked out of the cache if needed. - threadView.getMap().remove(thread.getIdLong()); + threadView.remove(thread.getType(), thread.getIdLong()); guildThreadView.getMap().remove(thread.getIdLong()); } } diff --git a/src/main/java/net/dv8tion/jda/internal/handle/ThreadDeleteHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/ThreadDeleteHandler.java index 57a83b034f..47cd3c637f 100644 --- a/src/main/java/net/dv8tion/jda/internal/handle/ThreadDeleteHandler.java +++ b/src/main/java/net/dv8tion/jda/internal/handle/ThreadDeleteHandler.java @@ -16,12 +16,14 @@ package net.dv8tion.jda.internal.handle; +import net.dv8tion.jda.api.entities.channel.Channel; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.events.channel.ChannelDeleteEvent; import net.dv8tion.jda.api.utils.data.DataObject; import net.dv8tion.jda.internal.JDAImpl; import net.dv8tion.jda.internal.entities.GuildImpl; import net.dv8tion.jda.internal.requests.WebSocketClient; +import net.dv8tion.jda.internal.utils.cache.ChannelCacheViewImpl; public class ThreadDeleteHandler extends SocketHandler { @@ -40,13 +42,15 @@ protected Long handleInternally(DataObject content) GuildImpl guild = (GuildImpl) getJDA().getGuildById(guildId); final long threadId = content.getLong("id"); - ThreadChannel thread = getJDA().getThreadChannelsView().remove(threadId); + ChannelCacheViewImpl channelsView = getJDA().getChannelsView(); + ThreadChannel thread = (ThreadChannel) channelsView.getElementById(threadId); if (thread == null || guild == null) { WebSocketClient.LOG.debug("THREAD_DELETE attempted to delete a thread that is not yet cached. JSON: {}", content); return null; } + channelsView.remove(thread.getType(), threadId); guild.getThreadChannelsView().remove(threadId); getJDA().handleEvent( diff --git a/src/main/java/net/dv8tion/jda/internal/handle/ThreadUpdateHandler.java b/src/main/java/net/dv8tion/jda/internal/handle/ThreadUpdateHandler.java index fb25f5e74c..7fedbc0d3e 100644 --- a/src/main/java/net/dv8tion/jda/internal/handle/ThreadUpdateHandler.java +++ b/src/main/java/net/dv8tion/jda/internal/handle/ThreadUpdateHandler.java @@ -17,6 +17,7 @@ package net.dv8tion.jda.internal.handle; import gnu.trove.set.TLongSet; +import net.dv8tion.jda.api.entities.channel.Channel; import net.dv8tion.jda.api.entities.channel.ChannelFlag; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.events.channel.update.*; @@ -27,7 +28,7 @@ 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; +import net.dv8tion.jda.internal.utils.cache.ChannelCacheViewImpl; import net.dv8tion.jda.internal.utils.cache.SortedSnowflakeCacheViewImpl; import java.util.List; @@ -191,9 +192,9 @@ protected Long handleInternally(DataObject content) if (thread.isArchived()) { SortedSnowflakeCacheViewImpl guildView = thread.getGuild().getThreadChannelsView(); - SnowflakeCacheViewImpl globalView = api.getThreadChannelsView(); + ChannelCacheViewImpl globalView = api.getChannelsView(); guildView.remove(threadId); - globalView.remove(threadId); + globalView.remove(thread.getType(), threadId); } return null;