Fix opening first channel on server start

Fixes #1547
This commit is contained in:
Pavel Djundik 2017-09-20 10:44:36 +03:00
parent 01eda0aac3
commit 649e9c3192
3 changed files with 11 additions and 6 deletions

View File

@ -50,7 +50,7 @@ socket.on("init", function(data) {
}); });
function openCorrectChannel(clientActive, serverActive) { function openCorrectChannel(clientActive, serverActive) {
let target; let target = $();
// Open last active channel // Open last active channel
if (clientActive > 0) { if (clientActive > 0) {
@ -58,17 +58,22 @@ function openCorrectChannel(clientActive, serverActive) {
} }
// Open window provided in location.hash // 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) + "']"); target = $("#footer, #sidebar").find("[data-target='" + escape(window.location.hash) + "']");
} }
// Open last active channel according to the server // Open last active channel according to the server
if (!target) { if (serverActive > 0 && target.length === 0) {
target = sidebar.find("[data-id='" + serverActive + "']"); 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 channel is found, open it
if (target) { if (target.length > 0) {
target.trigger("click", { target.trigger("click", {
replaceHistory: true replaceHistory: true
}); });

View File

@ -14,7 +14,7 @@ Chan.Type = {
SPECIAL: "special", SPECIAL: "special",
}; };
var id = 0; let id = 1;
function Chan(attr) { function Chan(attr) {
_.defaults(this, attr, { _.defaults(this, attr, {

View File

@ -5,7 +5,7 @@ var Chan = require("./chan");
module.exports = Network; module.exports = Network;
var id = 0; let id = 1;
function Network(attr) { function Network(attr) {
_.defaults(this, attr, { _.defaults(this, attr, {