Skip to content

Commit

Permalink
Added handling for PRESENCES_REPLACE
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Oct 18, 2017
1 parent 1def5e6 commit beb11d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,9 @@ protected Long handleInternally(JSONObject content)

//If the OnlineStatus is OFFLINE, ignore the event and return.
OnlineStatus status = OnlineStatus.fromKey(content.getString("status"));
if (status == OnlineStatus.OFFLINE)
return null;

//If this was for a Guild, cache it in the Guild for later use in GUILD_MEMBER_ADD
if (guild != null)
if (status != OnlineStatus.OFFLINE && guild != null)
guild.getCachedPresenceMap().put(userId, content);
}
return null;
Expand Down
38 changes: 20 additions & 18 deletions src/main/java/net/dv8tion/jda/core/requests/WebSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -922,20 +922,20 @@ protected void handleEvent(JSONObject raw)
return;
}
}
//
// // Needs special handling due to content of "d" being an array
// if(type.equals("PRESENCE_REPLACE"))
// {
// JSONArray presences = raw.getJSONArray("d");
// LOG.trace(String.format("%s -> %s", type, presences.toString()));
// PresenceUpdateHandler handler = new PresenceUpdateHandler(api, responseTotal);
// for (int i = 0; i < presences.length(); i++)
// {
// JSONObject presence = presences.getJSONObject(i);
// handler.handle(presence);
// }
// return;
// }

// Needs special handling due to content of "d" being an array
if (type.equals("PRESENCES_REPLACE"))
{
JSONArray presences = raw.getJSONArray("d");
LOG.trace(String.format("%s -> %s", type, presences.toString()));
PresenceUpdateHandler handler = getHandler("PRESENCE_UPDATE");
for (int i = 0; i < presences.length(); i++)
{
JSONObject presence = presences.getJSONObject(i);
handler.handle(responseTotal, presence);
}
return;
}

JSONObject content = raw.getJSONObject("d");
LOG.trace(String.format("%s -> %s", type, content.toString()));
Expand All @@ -946,7 +946,6 @@ protected void handleEvent(JSONObject raw)
{
//INIT types
case "READY":
//LOG.debug(String.format("%s -> %s", type, content.toString())); already logged on trace level
processingReady = true;
handleIdentifyRateLimit = false;
sessionId = content.getString("session_id");
Expand Down Expand Up @@ -1319,8 +1318,11 @@ private void setupHandlers()
handlers.put("VOICE_STATE_UPDATE", new VoiceStateUpdateHandler(api));

// Unused events
handlers.put("CHANNEL_PINS_UPDATE", new SocketHandler.NOPHandler(api));
handlers.put("WEBHOOKS_UPDATE", new SocketHandler.NOPHandler(api));
final SocketHandler.NOPHandler nopHandler = new SocketHandler.NOPHandler(api);
handlers.put("CHANNEL_PINS_UPDATE", nopHandler);
handlers.put("WEBHOOKS_UPDATE", nopHandler);
handlers.put("GUILD_INTEGRATIONS_UPDATE", nopHandler);
handlers.put("CHANNEL_PINS_ACK", nopHandler);

if (api.getAccountType() == AccountType.CLIENT)
{
Expand All @@ -1333,7 +1335,7 @@ private void setupHandlers()
handlers.put("RELATIONSHIP_REMOVE", new RelationshipRemoveHandler(api));

// Unused client events
handlers.put("MESSAGE_ACK", new SocketHandler.NOPHandler(api));
handlers.put("MESSAGE_ACK", nopHandler);
}
}

Expand Down

0 comments on commit beb11d5

Please sign in to comment.