diff --git a/client/js/lounge.js b/client/js/lounge.js index d73baa74..25302198 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -4,7 +4,6 @@ require("jquery-ui/ui/widgets/sortable"); const $ = require("jquery"); const moment = require("moment"); -const URI = require("urijs"); // our libraries require("./libs/jquery/stickyscroll"); @@ -346,49 +345,6 @@ $(function() { callback: (itemData) => closeChan($(`.networks .chan[data-target="${itemData}"]`)), }); - if ($(document.body).hasClass("public") && (window.location.hash === "#connect" || window.location.hash === "")) { - $("#connect").one("show", function() { - const params = URI(document.location.search).search(true); - - if ("channels" in params) { - params.join = params.channels; - } - - // Possible parameters: name, host, port, password, tls, nick, username, realname, join - // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Iterating_over_own_properties_only - for (let key in params) { - if (params.hasOwnProperty(key)) { - let value = params[key]; - - if (key === "join") { - const channels = value.split(","); - value = channels.map((c) => { - if (c.match(/^\w/)) { - return "#" + c; - } - - return c; - }).join(","); - } - - // \W searches for non-word characters - key = key.replace(/\W/g, ""); - - const element = $("#connect input[name='" + key + "']"); - - // if the element exists, it isn't disabled, and it isn't hidden - if (element.length > 0 && !element.is(":disabled") && !element.is(":hidden")) { - if (element.is(":checkbox")) { - element.prop("checked", (value === "1" || value === "true") ? true : false); - } else { - element.val(value); - } - } - } - } - }); - } - $(document).on("visibilitychange focus click", () => { if (sidebar.find(".highlight").length === 0) { utils.toggleNotificationMarkers(false); diff --git a/client/js/socket-events/configuration.js b/client/js/socket-events/configuration.js index 54232f50..e2674b9a 100644 --- a/client/js/socket-events/configuration.js +++ b/client/js/socket-events/configuration.js @@ -1,6 +1,7 @@ "use strict"; const $ = require("jquery"); +const URI = require("urijs"); const socket = require("../socket"); const templates = require("../../views"); const options = require("../options"); @@ -84,4 +85,38 @@ socket.on("configuration", function(data) { $(this).data("lastvalue", nick); }); }); + + if ($(document.body).hasClass("public")) { + const params = URI(document.location.search).search(true); + + for (let key in params) { + // Support `channels` as a compatibility alias with other clients + if (key === "channels") { + key = "join"; + } + + if (!data.defaults.hasOwnProperty(key)) { + continue; + } + + let value = params[key]; + + if (key === "join") { + value = value.split(",").map((chan) => { + if (!chan.match(/^[#&!+]/)) { + return `#${chan}`; + } + + return chan; + }).join(", "); + } + + // Override server provided defaults with parameters passed in the URL if they match the data type + switch (typeof data.defaults[key]) { + case "boolean": data.defaults[key] = value === "1" || value === "true"; break; + case "number": data.defaults[key] = Number(value); break; + case "string": data.defaults[key] = String(value); break; + } + } + } }); diff --git a/client/js/socket-events/init.js b/client/js/socket-events/init.js index 1e2af2a9..11debaef 100644 --- a/client/js/socket-events/init.js +++ b/client/js/socket-events/init.js @@ -23,10 +23,6 @@ socket.on("init", function(data) { if (data.networks.length === 0) { sidebar.find(".empty").show(); - - $("#footer").find(".connect").trigger("click", { - pushState: false, - }); } else { render.renderNetworks(data); } diff --git a/src/client.js b/src/client.js index d5f96d03..3752f118 100644 --- a/src/client.js +++ b/src/client.js @@ -177,7 +177,11 @@ Client.prototype.connect = function(args) { channels = args.join .replace(/,/g, " ") .split(/\s+/g) - .map(function(chan) { + .map((chan) => { + if (!chan.match(/^[#&!+]/)) { + chan = `#${chan}`; + } + return client.createChannel({ name: chan, });