Search in sources :

Example 1 with MessageDeleteEvent

use of org.javacord.api.event.message.MessageDeleteEvent 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);
    }
}
Also used : TextChannel(org.javacord.api.entity.channel.TextChannel) Server(org.javacord.api.entity.server.Server) JsonNode(com.fasterxml.jackson.databind.JsonNode) MessageDeleteEvent(org.javacord.api.event.message.MessageDeleteEvent) ServerChannel(org.javacord.api.entity.channel.ServerChannel) MessageDeleteEventImpl(org.javacord.core.event.message.MessageDeleteEventImpl) DispatchQueueSelector(org.javacord.core.util.event.DispatchQueueSelector)

Example 2 with MessageDeleteEvent

use of org.javacord.api.event.message.MessageDeleteEvent 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);
    }
}
Also used : TextChannel(org.javacord.api.entity.channel.TextChannel) Server(org.javacord.api.entity.server.Server) MessageDeleteEvent(org.javacord.api.event.message.MessageDeleteEvent) ServerChannel(org.javacord.api.entity.channel.ServerChannel) MessageDeleteEventImpl(org.javacord.core.event.message.MessageDeleteEventImpl) DispatchQueueSelector(org.javacord.core.util.event.DispatchQueueSelector)

Aggregations

ServerChannel (org.javacord.api.entity.channel.ServerChannel)2 TextChannel (org.javacord.api.entity.channel.TextChannel)2 Server (org.javacord.api.entity.server.Server)2 MessageDeleteEvent (org.javacord.api.event.message.MessageDeleteEvent)2 MessageDeleteEventImpl (org.javacord.core.event.message.MessageDeleteEventImpl)2 DispatchQueueSelector (org.javacord.core.util.event.DispatchQueueSelector)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1