From 09dee3d46a7f21a3fa6d0fb4112a21dfd296f029 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Sat, 3 Sep 2016 21:10:05 +0100 Subject: [PATCH] Fix ready never firing for truly unavailable guilds --- src/client/websocket/WebSocketManager.js | 10 +++++++++- src/client/websocket/packets/handlers/Ready.js | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/client/websocket/WebSocketManager.js b/src/client/websocket/WebSocketManager.js index 8f5240c89..22e84da56 100644 --- a/src/client/websocket/WebSocketManager.js +++ b/src/client/websocket/WebSocketManager.js @@ -44,6 +44,12 @@ class WebSocketManager { * @type {?string} */ this.gateway = null; + + /** + * Whether READY was emitted normally (all packets received) or not + * @type {boolean} + */ + this.normalReady = false; } /** @@ -51,6 +57,7 @@ class WebSocketManager { * @param {string} gateway the gateway to connect to */ connect(gateway) { + this.normalReady = false; this.status = Constants.Status.CONNECTING; /** * The WebSocket connection to the gateway @@ -200,7 +207,7 @@ class WebSocketManager { this.tryReconnect(); } - _emitReady() { + _emitReady(normal = true) { /** * Emitted when the Client becomes ready to start working * @@ -209,6 +216,7 @@ class WebSocketManager { this.status = Constants.Status.READY; this.client.emit(Constants.Events.READY); this.packetManager.handleQueue(); + this.normalReady = normal; } /** diff --git a/src/client/websocket/packets/handlers/Ready.js b/src/client/websocket/packets/handlers/Ready.js index f48c93d02..1283d46b0 100644 --- a/src/client/websocket/packets/handlers/Ready.js +++ b/src/client/websocket/packets/handlers/Ready.js @@ -27,6 +27,12 @@ class ReadyHandler extends AbstractHandler { client.once('ready', client.syncGuilds.bind(client)); + client.setTimeout(() => { + if (!client.ws.normalReady) { + client.ws._emitReady(false); + } + }, 1200 * data.guilds.length); + this.packetManager.ws.sessionID = data.session_id; this.packetManager.ws.checkIfReady();