Search in sources :

Example 1 with MessageEditListener

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

the class MessageUpdateHandler method handle.

@Override
public void handle(JSONObject packet) {
    String messageId = packet.getString("id");
    final Message message = api.getMessageById(messageId);
    if (message == null) {
        return;
    }
    final String oldContent = message.getContent();
    if (!packet.has("content")) {
        return;
    }
    ((ImplMessage) message).setContent(packet.getString("content"));
    listenerExecutorService.submit(new Runnable() {

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

Aggregations

Message (de.btobastian.javacord.entities.message.Message)1 ImplMessage (de.btobastian.javacord.entities.message.impl.ImplMessage)1 MessageEditListener (de.btobastian.javacord.listener.message.MessageEditListener)1 List (java.util.List)1