From 649e9c31920352f87a871db31449d78f3bf0a476 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Wed, 20 Sep 2017 10:44:36 +0300 Subject: [PATCH] Fix opening first channel on server start Fixes #1547 --- client/js/socket-events/init.js | 13 +++++++++---- src/models/chan.js | 2 +- src/models/network.js | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/client/js/socket-events/init.js b/client/js/socket-events/init.js index 6debd9d9..ec8d4988 100644 --- a/client/js/socket-events/init.js +++ b/client/js/socket-events/init.js @@ -50,7 +50,7 @@ socket.on("init", function(data) { }); function openCorrectChannel(clientActive, serverActive) { - let target; + let target = $(); // Open last active channel if (clientActive > 0) { @@ -58,17 +58,22 @@ function openCorrectChannel(clientActive, serverActive) { } // Open window provided in location.hash - if (!target && window.location.hash) { + if (target.length === 0 && window.location.hash) { target = $("#footer, #sidebar").find("[data-target='" + escape(window.location.hash) + "']"); } // Open last active channel according to the server - if (!target) { + if (serverActive > 0 && target.length === 0) { target = sidebar.find("[data-id='" + serverActive + "']"); } + // Open first available channel + if (target.length === 0) { + target = sidebar.find(".chan").first(); + } + // If target channel is found, open it - if (target) { + if (target.length > 0) { target.trigger("click", { replaceHistory: true }); diff --git a/src/models/chan.js b/src/models/chan.js index 3a9ddcec..b657d73e 100644 --- a/src/models/chan.js +++ b/src/models/chan.js @@ -14,7 +14,7 @@ Chan.Type = { SPECIAL: "special", }; -var id = 0; +let id = 1; function Chan(attr) { _.defaults(this, attr, { diff --git a/src/models/network.js b/src/models/network.js index 71a7dd7d..68bdf964 100644 --- a/src/models/network.js +++ b/src/models/network.js @@ -5,7 +5,7 @@ var Chan = require("./chan"); module.exports = Network; -var id = 0; +let id = 1; function Network(attr) { _.defaults(this, attr, {