From 0519c8a857dfef0372ac11d140e5830e1c6b6b5f Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 30 Aug 2018 20:16:26 +0300 Subject: [PATCH] Enforce lobby to be the first 0th channel when sorting --- src/client.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/client.js b/src/client.js index f5e9f475..9d555877 100644 --- a/src/client.js +++ b/src/client.js @@ -452,7 +452,17 @@ Client.prototype.sort = function(data) { return; } - network.channels.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id)); + network.channels.sort((a, b) => { + // Always sort lobby to the top regardless of what the client has sent + // Because there's a lot of code that presumes channels[0] is the lobby + if (a.type === Chan.Type.LOBBY) { + return -1; + } else if (b.type === Chan.Type.LOBBY) { + return 1; + } + + return order.indexOf(a.id) - order.indexOf(b.id); + }); // Sync order to connected clients this.emit("sync_sort", {