Skip to content

Commit

Permalink
Fix some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Aug 29, 2023
1 parent 253bedc commit c6d0d36
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -367,16 +369,15 @@ private void handleHideChildThreads(IThreadContainer channel)
for (ThreadChannel thread : threads)
{
GuildImpl guild = (GuildImpl) channel.getGuild();
SnowflakeCacheViewImpl<ThreadChannel>
guildThreadView = guild.getThreadChannelsView(),
threadView = getJDA().getThreadChannelsView();
SnowflakeCacheViewImpl<ThreadChannel> guildThreadView = guild.getThreadChannelsView();
ChannelCacheViewImpl<Channel> 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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<Channel> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;
Expand Down Expand Up @@ -191,9 +192,9 @@ protected Long handleInternally(DataObject content)
if (thread.isArchived())
{
SortedSnowflakeCacheViewImpl<ThreadChannel> guildView = thread.getGuild().getThreadChannelsView();
SnowflakeCacheViewImpl<ThreadChannel> globalView = api.getThreadChannelsView();
ChannelCacheViewImpl<Channel> globalView = api.getChannelsView();
guildView.remove(threadId);
globalView.remove(threadId);
globalView.remove(thread.getType(), threadId);
}

return null;
Expand Down

0 comments on commit c6d0d36

Please sign in to comment.