Skip to content

Commit

Permalink
Improve channel update handling (#2255)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Oct 23, 2022
1 parent daf17d1 commit 9741415
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 384 deletions.
Expand Up @@ -38,6 +38,8 @@
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import net.dv8tion.jda.internal.entities.channel.middleman.AbstractGuildChannelImpl;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IAgeRestrictedChannelMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.ISlowmodeChannelMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IThreadContainerMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IWebhookContainerMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.middleman.StandardGuildChannelMixin;
Expand All @@ -59,7 +61,9 @@ public class ForumChannelImpl extends AbstractGuildChannelImpl<ForumChannelImpl>
GuildChannelUnion,
StandardGuildChannelMixin<ForumChannelImpl>,
IWebhookContainerMixin<ForumChannelImpl>,
IThreadContainerMixin<ForumChannelImpl>
IThreadContainerMixin<ForumChannelImpl>,
IAgeRestrictedChannelMixin<ForumChannelImpl>,
ISlowmodeChannelMixin<ForumChannelImpl>
{
private final TLongObjectMap<PermissionOverride> overrides = MiscUtil.newLongMap();
private final SortedSnowflakeCacheViewImpl<ForumTag> tagCache = new SortedSnowflakeCacheViewImpl<>(ForumTag.class, ForumTag::getName, Comparator.naturalOrder());
Expand Down
Expand Up @@ -28,6 +28,7 @@
import net.dv8tion.jda.api.requests.restaction.ChannelAction;
import net.dv8tion.jda.internal.entities.GuildImpl;
import net.dv8tion.jda.internal.entities.channel.middleman.AbstractStandardGuildMessageChannelImpl;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.ISlowmodeChannelMixin;
import net.dv8tion.jda.internal.managers.channel.concrete.TextChannelManagerImpl;
import net.dv8tion.jda.internal.utils.Checks;

Expand All @@ -38,7 +39,8 @@

public class TextChannelImpl extends AbstractStandardGuildMessageChannelImpl<TextChannelImpl> implements
TextChannel,
DefaultGuildChannelUnion
DefaultGuildChannelUnion,
ISlowmodeChannelMixin<TextChannelImpl>
{
private int slowmode;

Expand Down
Expand Up @@ -41,6 +41,7 @@
import net.dv8tion.jda.internal.entities.EntityBuilder;
import net.dv8tion.jda.internal.entities.GuildImpl;
import net.dv8tion.jda.internal.entities.channel.middleman.AbstractGuildChannelImpl;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.ISlowmodeChannelMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildMessageChannelMixin;
import net.dv8tion.jda.internal.managers.channel.concrete.ThreadChannelManagerImpl;
import net.dv8tion.jda.internal.requests.DeferredRestAction;
Expand All @@ -60,7 +61,8 @@

public class ThreadChannelImpl extends AbstractGuildChannelImpl<ThreadChannelImpl> implements
ThreadChannel,
GuildMessageChannelMixin<ThreadChannelImpl>
GuildMessageChannelMixin<ThreadChannelImpl>,
ISlowmodeChannelMixin<ThreadChannelImpl>
{
private final ChannelType type;
private final CacheView.SimpleCacheView<ThreadMember> threadMembers = new CacheView.SimpleCacheView<>(ThreadMember.class, null);
Expand Down
Expand Up @@ -30,6 +30,7 @@
import net.dv8tion.jda.api.utils.MiscUtil;
import net.dv8tion.jda.internal.entities.GuildImpl;
import net.dv8tion.jda.internal.entities.channel.middleman.AbstractStandardGuildChannelImpl;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IAgeRestrictedChannelMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IWebhookContainerMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.middleman.AudioChannelMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildMessageChannelMixin;
Expand All @@ -46,7 +47,8 @@ public class VoiceChannelImpl extends AbstractStandardGuildChannelImpl<VoiceChan
VoiceChannel,
GuildMessageChannelMixin<VoiceChannelImpl>,
AudioChannelMixin<VoiceChannelImpl>,
IWebhookContainerMixin<VoiceChannelImpl>
IWebhookContainerMixin<VoiceChannelImpl>,
IAgeRestrictedChannelMixin<VoiceChannelImpl>
{
private final TLongObjectMap<Member> connectedMembers = MiscUtil.newLongMap();

Expand Down
@@ -0,0 +1,25 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.internal.entities.channel.mixin.attribute;

import net.dv8tion.jda.api.entities.channel.attribute.IAgeRestrictedChannel;
import net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildChannelMixin;

public interface IAgeRestrictedChannelMixin<T extends IAgeRestrictedChannelMixin<T>> extends GuildChannelMixin<T>, IAgeRestrictedChannel
{
T setNSFW(boolean ageRestricted);
}
Expand Up @@ -25,7 +25,8 @@ public interface ICategorizableChannelMixin<T extends ICategorizableChannelMixin
{
// ---- Default implementations of interface ----
@Override
default boolean isSynced() {
default boolean isSynced()
{
IPermissionContainerMixin<?> parent = (IPermissionContainerMixin<?>) getParentCategory();
if (parent == null)
return true; // Channels without a parent category are always considered synced. Also the case for categories.
Expand Down
@@ -0,0 +1,25 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.internal.entities.channel.mixin.attribute;

import net.dv8tion.jda.api.entities.channel.attribute.ISlowmodeChannel;
import net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildChannelMixin;

public interface ISlowmodeChannelMixin<T extends ISlowmodeChannelMixin<T>> extends GuildChannelMixin<T>, ISlowmodeChannel
{
T setSlowmode(int slowmode);
}
@@ -0,0 +1,26 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.dv8tion.jda.internal.entities.channel.mixin.attribute;

import net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildChannelMixin;

public interface ITopicChannelMixin<T extends ITopicChannelMixin<T>> extends GuildChannelMixin<T>
{
T setTopic(String topic);

String getTopic();
}
Expand Up @@ -19,7 +19,9 @@
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.middleman.StandardGuildMessageChannel;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IAgeRestrictedChannelMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IThreadContainerMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.ITopicChannelMixin;
import net.dv8tion.jda.internal.entities.channel.mixin.attribute.IWebhookContainerMixin;

import javax.annotation.Nonnull;
Expand All @@ -29,7 +31,9 @@ public interface StandardGuildMessageChannelMixin<T extends StandardGuildMessage
StandardGuildChannelMixin<T>,
GuildMessageChannelMixin<T>,
IThreadContainerMixin<T>,
IWebhookContainerMixin<T>
IAgeRestrictedChannelMixin<T>,
IWebhookContainerMixin<T>,
ITopicChannelMixin<T>
{
// ---- Default implementations of interface ----
@Override
Expand All @@ -40,9 +44,4 @@ default boolean canTalk(@Nonnull Member member)

return member.hasPermission(this, Permission.VIEW_CHANNEL, Permission.MESSAGE_SEND);
}

// ---- State Accessors ----
T setTopic(String topic);

T setNSFW(boolean nsfw);
}

0 comments on commit 9741415

Please sign in to comment.