Repository: thelounge/thelounge (ts)

Issue:
Optional Per-Network Away Message
I don't think I saw anyone raise this feature. I saw that we have away/auto-away as an option. I think it'd be nice to be able to set the away message per-network. I can do this on ZNC, but ZNC can't detect when I'm idle or away with the Lounge (that I know of).

I think this might be a factor in some other issues. This could build on #1996? Possibly allow for a "system-wide default" away and a per-network over-ride to be available?

Pull request description:
Add network specific leave message
I do find his idea quite reasonable and would like to see this happening 

Patch:
diff --git a/client/components/NetworkForm.vue b/client/components/NetworkForm.vue
index ee9ff0d3..5024ef15 100644
--- a/client/components/NetworkForm.vue
+++ b/client/components/NetworkForm.vue
@@ -167,6 +167,16 @@
 					maxlength="300"
 				/>
 			</div>
+			<div class="connect-row">
+				<label for="connect:leaveMessage">Away message</label>
+				<input
+					id="connect:leaveMessage"
+					v-model="defaults.leaveMessage"
+					class="input"
+					name="leaveMessage"
+					placeholder="The Lounge - https://thelounge.chat"
+				/>
+			</div>
 			<template v-if="defaults.uuid && !$store.state.serverConfiguration.public">
 				<div class="connect-row">
 					<label for="connect:commands">
diff --git a/defaults/config.js b/defaults/config.js
index 264d1f5d..9f8a5493 100644
--- a/defaults/config.js
+++ b/defaults/config.js
@@ -218,6 +218,7 @@ module.exports = {
 	//   numbers from 0 to 9. For example, `Guest%%%` may become `Guest123`.
 	// - `username`: User name.
 	// - `realname`: Real name.
+	// - `leaveMessage`: Network specific leave message (overrides global leaveMessage)
 	// - `join`: Comma-separated list of channels to auto-join once connected.
 	//
 	// This value is set to connect to the official channel of The Lounge on
@@ -248,6 +249,7 @@ module.exports = {
 		username: "thelounge",
 		realname: "The Lounge User",
 		join: "#thelounge",
+		leaveMessage: "",
 	},
 
 	// ### `lockNetwork`
diff --git a/src/client.js b/src/client.js
index 6f9fd023..064c5e50 100644
--- a/src/client.js
+++ b/src/client.js
@@ -241,6 +241,7 @@ Client.prototype.connect = function (args, isStartup = false) {
 		nick: String(args.nick || ""),
 		username: String(args.username || ""),
 		realname: String(args.realname || ""),
+		leaveMessage: String(args.leaveMessage || ""),
 		sasl: String(args.sasl || ""),
 		saslAccount: String(args.saslAccount || ""),
 		saslPassword: String(args.saslPassword || ""),
@@ -649,7 +650,7 @@ Client.prototype.quit = function (signOut) {
 	}
 
 	this.networks.forEach((network) => {
-		network.quit(Helper.config.leaveMessage);
+		network.quit();
 		network.destroy();
 	});
 
diff --git a/src/models/network.js b/src/models/network.js
index e137a137..bc2dbce1 100644
--- a/src/models/network.js
+++ b/src/models/network.js
@@ -35,6 +35,7 @@ function Network(attr) {
 		commands: [],
 		username: "",
 		realname: "",
+		leaveMessage: "",
 		sasl: "",
 		saslAccount: "",
 		saslPassword: "",
@@ -82,6 +83,7 @@ Network.prototype.validate = function (client) {
 
 	this.username = cleanString(this.username) || "thelounge";
 	this.realname = cleanString(this.realname) || "The Lounge User";
+	this.leaveMessage = cleanString(this.leaveMessage);
 	this.password = cleanString(this.password);
 	this.host = cleanString(this.host).toLowerCase();
 	this.name = cleanString(this.name);
@@ -267,6 +269,7 @@ Network.prototype.edit = function (client, args) {
 	this.password = String(args.password || "");
 	this.username = String(args.username || "");
 	this.realname = String(args.realname || "");
+	this.leaveMessage = String(args.leaveMessage || "");
 	this.sasl = String(args.sasl || "");
 	this.saslAccount = String(args.saslAccount || "");
 	this.saslPassword = String(args.saslPassword || "");
@@ -436,7 +439,7 @@ Network.prototype.quit = function (quitMessage) {
 	// https://ircv3.net/specs/extensions/sts#rescheduling-expiry-on-disconnect
 	STSPolicies.refreshExpiration(this.host);
 
-	this.irc.quit(quitMessage || Helper.config.leaveMessage);
+	this.irc.quit(quitMessage || this.leaveMessage || Helper.config.leaveMessage);
 };
 
 Network.prototype.exportForEdit = function () {
@@ -447,6 +450,7 @@ Network.prototype.exportForEdit = function () {
 		"password",
 		"username",
 		"realname",
+		"leaveMessage",
 		"sasl",
 		"saslAccount",
 		"saslPassword",
@@ -481,6 +485,7 @@ Network.prototype.export = function () {
 		"password",
 		"username",
 		"realname",
+		"leaveMessage",
 		"sasl",
 		"saslAccount",
 		"saslPassword",
diff --git a/src/plugins/inputs/part.js b/src/plugins/inputs/part.js
index f049d5b8..d4ba095a 100644
--- a/src/plugins/inputs/part.js
+++ b/src/plugins/inputs/part.js
@@ -48,7 +48,7 @@ exports.input = function (network, chan, cmd, args) {
 		});
 		this.save();
 	} else {
-		const partMessage = args.join(" ") || Helper.config.leaveMessage;
+		const partMessage = args.join(" ") || network.leaveMessage || Helper.config.leaveMessage;
 		network.irc.part(target.name, partMessage);
 	}
 


Test patch:
diff --git a/test/models/network.js b/test/models/network.js
index 3308bbc6..6d6d8119 100644
--- a/test/models/network.js
+++ b/test/models/network.js
@@ -40,6 +40,7 @@ describe("Network", function () {
 				password: "",
 				username: "",
 				realname: "",
+				leaveMessage: "",
 				sasl: "plain",
 				saslAccount: "testaccount",
 				saslPassword: "testpassword",