Search in sources :

Example 1 with TypingStartListener

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

the class TypingStartHandler method handle.

@Override
public void handle(JSONObject packet) {
    Channel channelTemp = null;
    String channelId = packet.getString("channel_id");
    Iterator<Server> serverIterator = api.getServers().iterator();
    while (serverIterator.hasNext()) {
        channelTemp = serverIterator.next().getChannelById(channelId);
        if (channelTemp != null) {
            break;
        }
    }
    final Channel channel = channelTemp;
    String userId = packet.getString("user_id");
    final User user;
    try {
        user = api.getUserById(userId).get();
    } catch (InterruptedException | ExecutionException e) {
        return;
    }
    listenerExecutorService.submit(new Runnable() {

        @Override
        public void run() {
            List<TypingStartListener> listeners = api.getListeners(TypingStartListener.class);
            synchronized (listeners) {
                for (TypingStartListener listener : listeners) {
                    try {
                        listener.onTypingStart(api, user, channel);
                    } catch (Throwable t) {
                        logger.warn("Uncaught exception in TypingStartListener!", t);
                    }
                }
            }
        }
    });
}
Also used : User(de.btobastian.javacord.entities.User) Server(de.btobastian.javacord.entities.Server) Channel(de.btobastian.javacord.entities.Channel) TypingStartListener(de.btobastian.javacord.listener.message.TypingStartListener) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Channel (de.btobastian.javacord.entities.Channel)1 Server (de.btobastian.javacord.entities.Server)1 User (de.btobastian.javacord.entities.User)1 TypingStartListener (de.btobastian.javacord.listener.message.TypingStartListener)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1