Use nick as a realname fallback

Currently the realname is set to an advertisement if it isn't explicitly
set by the user.
Some clients started to show the realname as a display name in their
UI, which makes this tedious as you'll end up with gazillion "The Lounge
User" entries.

To avoid this, set the realname to the nick on first connect, so that
it is useful.
Note that this isn't done on nick changes, but only on the initial
connect step.

Fixes: https://github.com/thelounge/thelounge/issues/4527
This commit is contained in:
Reto Brunner 2022-08-28 11:17:14 +02:00
parent 117c5fa3fd
commit 30e9f45fac
3 changed files with 25 additions and 4 deletions

View File

@ -241,7 +241,7 @@ module.exports = {
// - `nick`: Nick name. Percent signs (`%`) will be replaced by random // - `nick`: Nick name. Percent signs (`%`) will be replaced by random
// numbers from 0 to 9. For example, `Guest%%%` may become `Guest123`. // numbers from 0 to 9. For example, `Guest%%%` may become `Guest123`.
// - `username`: User name. // - `username`: User name.
// - `realname`: Real name. // - `realname`: Real name displayed by some clients. Defaults to the nick if set to ""
// - `leaveMessage`: Network specific leave message (overrides global leaveMessage) // - `leaveMessage`: Network specific leave message (overrides global leaveMessage)
// - `join`: Comma-separated list of channels to auto-join once connected. // - `join`: Comma-separated list of channels to auto-join once connected.
// //
@ -271,7 +271,7 @@ module.exports = {
rejectUnauthorized: true, rejectUnauthorized: true,
nick: "thelounge%%", nick: "thelounge%%",
username: "thelounge", username: "thelounge",
realname: "The Lounge User", realname: "",
join: "#thelounge", join: "#thelounge",
leaveMessage: "", leaveMessage: "",
}, },

View File

@ -190,7 +190,7 @@ class Network {
} }
this.username = cleanString(this.username) || "thelounge"; this.username = cleanString(this.username) || "thelounge";
this.realname = cleanString(this.realname) || "The Lounge User"; this.realname = cleanString(this.realname) || this.nick;
this.leaveMessage = cleanString(this.leaveMessage); this.leaveMessage = cleanString(this.leaveMessage);
this.password = cleanString(this.password); this.password = cleanString(this.password);
this.host = cleanString(this.host).toLowerCase(); this.host = cleanString(this.host).toLowerCase();

View File

@ -145,7 +145,7 @@ describe("Network", function () {
expect(network.validate({} as any)).to.be.true; expect(network.validate({} as any)).to.be.true;
expect(network.nick).to.equal("thelounge"); expect(network.nick).to.equal("thelounge");
expect(network.username).to.equal("thelounge"); expect(network.username).to.equal("thelounge");
expect(network.realname).to.equal("The Lounge User"); expect(network.realname).to.equal("thelounge");
expect(network.port).to.equal(6667); expect(network.port).to.equal(6667);
const network2 = new Network({ const network2 = new Network({
@ -186,6 +186,27 @@ describe("Network", function () {
Config.values.lockNetwork = false; Config.values.lockNetwork = false;
}); });
it("realname should be set to nick only if realname is empty", function () {
const network = new Network({
host: "localhost",
nick: "dummy",
});
expect(network.validate({} as any)).to.be.true;
expect(network.nick).to.equal("dummy");
expect(network.realname).to.equal("dummy");
const network2 = new Network({
host: "localhost",
nick: "dummy",
realname: "notdummy",
});
expect(network2.validate({} as any)).to.be.true;
expect(network2.nick).to.equal("dummy");
expect(network2.realname).to.equal("notdummy");
});
it("should apply STS policies iff they match", function () { it("should apply STS policies iff they match", function () {
const client = {idMsg: 1, emit() {}} as any; const client = {idMsg: 1, emit() {}} as any;
STSPolicies.update("irc.example.com", 7000, 3600); STSPolicies.update("irc.example.com", 7000, 3600);