use of org.javacord.core.event.message.MessageDeleteEventImpl in project Javacord by BtoBastian.
the class MessageDeleteBulkHandler method handle.
@Override
public void handle(JsonNode packet) {
long channelId = Long.parseLong(packet.get("channel_id").asText());
Optional<TextChannel> optionalChannel = api.getTextChannelById(channelId);
if (optionalChannel.isPresent()) {
TextChannel channel = optionalChannel.get();
for (JsonNode messageIdJson : packet.get("ids")) {
long messageId = messageIdJson.asLong();
MessageDeleteEvent event = new MessageDeleteEventImpl(api, messageId, channel);
api.getCachedMessageById(messageId).ifPresent(((MessageCacheImpl) channel.getMessageCache())::removeMessage);
api.removeMessageFromCache(messageId);
Optional<Server> optionalServer = channel.asServerChannel().map(ServerChannel::getServer);
api.getEventDispatcher().dispatchMessageDeleteEvent(optionalServer.map(DispatchQueueSelector.class::cast).orElse(api), messageId, optionalServer.orElse(null), channel, event);
}
} else {
LoggerUtil.logMissingChannel(logger, channelId);
}
}
use of org.javacord.core.event.message.MessageDeleteEventImpl in project Javacord by BtoBastian.
the class MessageDeleteHandler method handle.
@Override
public void handle(JsonNode packet) {
long messageId = packet.get("id").asLong();
long channelId = packet.get("channel_id").asLong();
Optional<TextChannel> optionalChannel = api.getTextChannelById(channelId);
if (optionalChannel.isPresent()) {
TextChannel channel = optionalChannel.get();
MessageDeleteEvent event = new MessageDeleteEventImpl(api, messageId, channel);
api.getCachedMessageById(messageId).ifPresent(((MessageCacheImpl) channel.getMessageCache())::removeMessage);
api.removeMessageFromCache(messageId);
Optional<Server> optionalServer = channel.asServerChannel().map(ServerChannel::getServer);
api.getEventDispatcher().dispatchMessageDeleteEvent(optionalServer.map(DispatchQueueSelector.class::cast).orElse(api), messageId, optionalServer.orElse(null), channel, event);
api.removeObjectListeners(Message.class, messageId);
} else {
LoggerUtil.logMissingChannel(logger, channelId);
}
}
Aggregations