Merge pull request #2378 from thelounge/xpaw/fix-2327
Add prefix to channels from connect window
This commit is contained in:
commit
f5a8f23d2b
@ -4,7 +4,6 @@
|
|||||||
require("jquery-ui/ui/widgets/sortable");
|
require("jquery-ui/ui/widgets/sortable");
|
||||||
const $ = require("jquery");
|
const $ = require("jquery");
|
||||||
const moment = require("moment");
|
const moment = require("moment");
|
||||||
const URI = require("urijs");
|
|
||||||
|
|
||||||
// our libraries
|
// our libraries
|
||||||
require("./libs/jquery/stickyscroll");
|
require("./libs/jquery/stickyscroll");
|
||||||
@ -346,49 +345,6 @@ $(function() {
|
|||||||
callback: (itemData) => closeChan($(`.networks .chan[data-target="${itemData}"]`)),
|
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", () => {
|
$(document).on("visibilitychange focus click", () => {
|
||||||
if (sidebar.find(".highlight").length === 0) {
|
if (sidebar.find(".highlight").length === 0) {
|
||||||
utils.toggleNotificationMarkers(false);
|
utils.toggleNotificationMarkers(false);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const $ = require("jquery");
|
const $ = require("jquery");
|
||||||
|
const URI = require("urijs");
|
||||||
const socket = require("../socket");
|
const socket = require("../socket");
|
||||||
const templates = require("../../views");
|
const templates = require("../../views");
|
||||||
const options = require("../options");
|
const options = require("../options");
|
||||||
@ -84,4 +85,38 @@ socket.on("configuration", function(data) {
|
|||||||
$(this).data("lastvalue", nick);
|
$(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -23,10 +23,6 @@ socket.on("init", function(data) {
|
|||||||
|
|
||||||
if (data.networks.length === 0) {
|
if (data.networks.length === 0) {
|
||||||
sidebar.find(".empty").show();
|
sidebar.find(".empty").show();
|
||||||
|
|
||||||
$("#footer").find(".connect").trigger("click", {
|
|
||||||
pushState: false,
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
render.renderNetworks(data);
|
render.renderNetworks(data);
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,11 @@ Client.prototype.connect = function(args) {
|
|||||||
channels = args.join
|
channels = args.join
|
||||||
.replace(/,/g, " ")
|
.replace(/,/g, " ")
|
||||||
.split(/\s+/g)
|
.split(/\s+/g)
|
||||||
.map(function(chan) {
|
.map((chan) => {
|
||||||
|
if (!chan.match(/^[#&!+]/)) {
|
||||||
|
chan = `#${chan}`;
|
||||||
|
}
|
||||||
|
|
||||||
return client.createChannel({
|
return client.createChannel({
|
||||||
name: chan,
|
name: chan,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user