Enable setting network commands on network creation

This commit is contained in:
Max Leiter 2022-05-01 02:15:23 -07:00
parent 9dbb6e5e19
commit e4e57b00c0
No known key found for this signature in database
GPG key ID: A3512F2F2F17EBDA
3 changed files with 34 additions and 18 deletions

View file

@ -252,7 +252,18 @@
placeholder="The Lounge - https://thelounge.chat"
/>
</div>
<template v-if="defaults.uuid && !$store.state.serverConfiguration.public">
<template v-if="!defaults.uuid">
<div class="connect-row">
<label for="connect:channels">Channels</label>
<input
id="connect:channels"
v-model="defaults.join"
class="input"
name="join"
/>
</div>
</template>
<template v-if="!$store.state.serverConfiguration.public">
<div class="connect-row">
<label for="connect:commands">
Commands
@ -260,7 +271,7 @@
class="tooltipped tooltipped-ne tooltipped-no-delay"
aria-label="One /command per line.
Each command will be executed in
the server tab on new connection"
the server tab on every connection."
>
<button class="extra-help" />
</span>
@ -276,17 +287,6 @@ the server tab on new connection"
/>
</div>
</template>
<template v-else-if="!defaults.uuid">
<div class="connect-row">
<label for="connect:channels">Channels</label>
<input
id="connect:channels"
v-model="defaults.join"
class="input"
name="join"
/>
</div>
</template>
<template v-if="$store.state.serverConfiguration.public">
<template v-if="config.lockNetwork">

View file

@ -22,6 +22,18 @@ const fieldsForClient = {
serverOptions: true,
};
const parseCommands = function (commands) {
if (!commands) {
return [];
}
// Split commands into an array
return commands
.replace(/\r\n|\r|\n/g, "\n")
.split("\n")
.filter((command) => command.length > 0);
};
function Network(attr) {
_.defaults(this, attr, {
name: "",
@ -83,6 +95,10 @@ function Network(attr) {
this.channels.every((chan) => chan.muted || chan.type === Chan.Type.SPECIAL),
})
);
if (this.commands && !Array.isArray(this.commands)) {
this.commands = parseCommands(this.commands);
}
}
Network.prototype.validate = function (client) {
@ -298,10 +314,7 @@ Network.prototype.edit = function (client, args) {
this.proxyEnabled = !!args.proxyEnabled;
// Split commands into an array
this.commands = String(args.commands || "")
.replace(/\r\n|\r|\n/g, "\n")
.split("\n")
.filter((command) => command.length > 0);
this.commands = parseCommands(String(args.commands || ""));
// Sync lobby channel name
this.channels[0].name = this.name;

View file

@ -395,9 +395,12 @@ function initializeClient(socket, client, token, lastMessage, openChannel) {
if (_.isPlainObject(data)) {
// prevent people from overriding webirc settings
data.uuid = null;
data.commands = null;
data.ignoreList = null;
if (Helper.config.webirc !== null) {
data.commands = null;
}
client.connect(data);
}
});