Search in sources :

Example 1 with MessageDeleteListener

use of de.btobastian.javacord.listener.message.MessageDeleteListener in project Javacord by BtoBastian.

the class MessageBulkDeleteHandler method handle.

@Override
public void handle(JSONObject packet) {
    JSONArray messageIds = packet.getJSONArray("ids");
    for (int i = 0; i < messageIds.length(); i++) {
        String messageId = messageIds.getString(i);
        final Message message = api.getMessageById(messageId);
        if (message == null) {
            // no cached version available
            return;
        }
        listenerExecutorService.submit(new Runnable() {

            @Override
            public void run() {
                List<MessageDeleteListener> listeners = api.getListeners(MessageDeleteListener.class);
                synchronized (listeners) {
                    for (MessageDeleteListener listener : listeners) {
                        try {
                            listener.onMessageDelete(api, message);
                        } catch (Throwable t) {
                            logger.warn("Uncaught exception in MessageDeleteListener!", t);
                        }
                    }
                }
            }
        });
    }
}
Also used : Message(de.btobastian.javacord.entities.message.Message) MessageDeleteListener(de.btobastian.javacord.listener.message.MessageDeleteListener) JSONArray(org.json.JSONArray) List(java.util.List)

Example 2 with MessageDeleteListener

use of de.btobastian.javacord.listener.message.MessageDeleteListener in project Javacord by BtoBastian.

the class MessageDeleteHandler method handle.

@Override
public void handle(JSONObject packet) {
    String messageId = packet.getString("id");
    final Message message = api.getMessageById(messageId);
    if (message == null) {
        // no cached version available
        return;
    }
    synchronized (message) {
        if (message.isDeleted()) {
            // already called listener
            return;
        } else {
            ((ImplMessage) message).setDeleted(true);
        }
    }
    listenerExecutorService.submit(new Runnable() {

        @Override
        public void run() {
            List<MessageDeleteListener> listeners = api.getListeners(MessageDeleteListener.class);
            synchronized (listeners) {
                for (MessageDeleteListener listener : listeners) {
                    try {
                        listener.onMessageDelete(api, message);
                    } catch (Throwable t) {
                        logger.warn("Uncaught exception in MessageDeleteListener!", t);
                    }
                }
            }
        }
    });
}
Also used : Message(de.btobastian.javacord.entities.message.Message) ImplMessage(de.btobastian.javacord.entities.message.impl.ImplMessage) MessageDeleteListener(de.btobastian.javacord.listener.message.MessageDeleteListener) ImplMessage(de.btobastian.javacord.entities.message.impl.ImplMessage) List(java.util.List)

Aggregations

Message (de.btobastian.javacord.entities.message.Message)2 MessageDeleteListener (de.btobastian.javacord.listener.message.MessageDeleteListener)2 List (java.util.List)2 ImplMessage (de.btobastian.javacord.entities.message.impl.ImplMessage)1 JSONArray (org.json.JSONArray)1