use of org.javacord.core.entity.channel.ServerThreadChannelImpl in project Javacord by BtoBastian.
the class ThreadUpdateHandler method handleThread.
private void handleThread(final JsonNode jsonChannel) {
final long channelId = jsonChannel.get("id").asLong();
final long serverId = jsonChannel.get("guild_id").asLong();
final ServerImpl server = api.getServerById(serverId).map(ServerImpl.class::cast).orElse(null);
if (server == null) {
logger.warn("Unable to find server with id {}", serverId);
return;
}
final ServerThreadChannelImpl thread = (ServerThreadChannelImpl) server.getOrCreateServerThreadChannel(jsonChannel);
// Handling whether the name has changed
final String oldName = thread.getName();
final String newName = jsonChannel.get("name").asText();
if (!Objects.deepEquals(oldName, newName)) {
thread.setName(newName);
final ServerChannelChangeNameEvent event = new ServerChannelChangeNameEventImpl(thread, newName, oldName);
if (server.isReady()) {
api.getEventDispatcher().dispatchServerChannelChangeNameEvent((DispatchQueueSelector) thread.getServer(), thread.getServer(), thread, event);
}
}
}
use of org.javacord.core.entity.channel.ServerThreadChannelImpl in project Javacord by BtoBastian.
the class ThreadMembersUpdateHandler method handle.
@Override
public void handle(final JsonNode packet) {
final long channelId = packet.get("id").asLong();
final long serverId = packet.get("guild_id").asLong();
final ServerImpl server = api.getServerById(serverId).map(ServerImpl.class::cast).orElse(null);
if (server == null) {
logger.warn("Unable to find server with id {}", serverId);
return;
}
final ServerThreadChannelImpl thread = server.getThreadChannelById(channelId).map(ServerThreadChannelImpl.class::cast).orElse(null);
if (thread == null) {
logger.warn("Unable to find thread with id {}", channelId);
return;
}
final int memberCount = packet.get("member_count").asInt();
final List<Long> removedMemberIds = new ArrayList<>();
if (packet.has("removed_member_ids")) {
for (final JsonNode removedMemberId : packet.get("removed_member_ids")) {
removedMemberIds.add(removedMemberId.asLong());
}
}
final List<ThreadMember> addedMembers = new ArrayList<>();
if (packet.has("added_members")) {
for (final JsonNode addedMember : packet.get("added_members")) {
addedMembers.add(new ThreadMemberImpl(api, server, addedMember));
}
}
thread.setMembers(addedMembers);
final ThreadMembersUpdateEvent event = new ThreadMembersUpdateEventImpl(thread, server, memberCount, addedMembers, removedMemberIds);
api.getEventDispatcher().dispatchThreadMembersUpdateEvent(server, server, thread, event);
}
use of org.javacord.core.entity.channel.ServerThreadChannelImpl in project Javacord by BtoBastian.
the class ServerImpl method getOrCreateServerThreadChannel.
/**
* Gets or creates a server text channel.
*
* @param data The json data of the channel.
* @return The server text channel.
*/
public ServerThreadChannel getOrCreateServerThreadChannel(final JsonNode data) {
final long id = Long.parseLong(data.get("id").asText());
final ChannelType type = ChannelType.fromId(data.get("type").asInt());
synchronized (this) {
switch(type) {
case SERVER_PUBLIC_THREAD:
case SERVER_PRIVATE_THREAD:
case SERVER_NEWS_THREAD:
return getThreadChannelById(id).orElseGet(() -> new ServerThreadChannelImpl(api, this, data));
default:
// Invalid channel type
return null;
}
}
}
Aggregations