Search in sources :

Example 1 with UserChangeStatusEventImpl

use of org.javacord.core.event.user.UserChangeStatusEventImpl in project Javacord by BtoBastian.

the class PresenceUpdateHandler method dispatchUserStatusChangeEventIfChangeDetected.

private void dispatchUserStatusChangeEventIfChangeDetected(long userId, UserStatus newStatus, UserStatus oldStatus, Map<DiscordClient, UserStatus> newClientStatus, Map<DiscordClient, UserStatus> oldClientStatus) {
    UserImpl user = api.getCachedUserById(userId).map(UserImpl.class::cast).orElse(null);
    // Only dispatch the event if something changed
    boolean shouldDispatch = false;
    if (newClientStatus != oldClientStatus) {
        shouldDispatch = true;
    }
    for (DiscordClient client : DiscordClient.values()) {
        if (newClientStatus.get(client) != oldClientStatus.get(client)) {
            shouldDispatch = true;
        }
    }
    if (!shouldDispatch) {
        return;
    }
    UserChangeStatusEvent event = new UserChangeStatusEventImpl(api, userId, newStatus, oldStatus, newClientStatus, oldClientStatus);
    api.getEventDispatcher().dispatchUserChangeStatusEvent(api, user == null ? Collections.emptySet() : user.getMutualServers(), user == null ? Collections.emptySet() : Collections.singleton(user), event);
}
Also used : DiscordClient(org.javacord.api.entity.DiscordClient) UserChangeStatusEventImpl(org.javacord.core.event.user.UserChangeStatusEventImpl) UserChangeStatusEvent(org.javacord.api.event.user.UserChangeStatusEvent) UserImpl(org.javacord.core.entity.user.UserImpl)

Aggregations

DiscordClient (org.javacord.api.entity.DiscordClient)1 UserChangeStatusEvent (org.javacord.api.event.user.UserChangeStatusEvent)1 UserImpl (org.javacord.core.entity.user.UserImpl)1 UserChangeStatusEventImpl (org.javacord.core.event.user.UserChangeStatusEventImpl)1