mirror of
https://github.com/thelounge/thelounge.git
synced 2026-03-14 14:35:50 +01:00
Fix state machine to preserve preferred nick without fallbacks
- error.ts: Store user's preferred nick (network.nick) in keepNick, not session nick - error.ts: Remove unnecessary client nick emit after fallback - welcome.ts: Don't overwrite preferred nick when registered with fallback - Allows existing quit handler to naturally reclaim preferred nick when it becomes available
This commit is contained in:
parent
b2e3112806
commit
a123461a84
2 changed files with 18 additions and 12 deletions
|
|
@ -40,11 +40,9 @@ export default <IrcEventHandler>function (irc, network) {
|
|||
if (irc.connection.registered === false && !Config.values.public) {
|
||||
message += " An attempt to use it will be made when this nick quits.";
|
||||
|
||||
// Clients usually get nick in use on connect when reconnecting to a network
|
||||
// after a network failure (like ping timeout), and as a result of that,
|
||||
// TL will append a random number to the nick.
|
||||
// keepNick will try to set the original nick name back if it sees a QUIT for that nick.
|
||||
network.keepNick = irc.user.nick;
|
||||
// Store the user's preferred nick in keepNick so the quit handler can reclaim it
|
||||
// This is the user's actual preference from network.nick, not a fallback
|
||||
network.keepNick = network.nick;
|
||||
}
|
||||
|
||||
const lobby = network.getLobby();
|
||||
|
|
@ -57,20 +55,16 @@ export default <IrcEventHandler>function (irc, network) {
|
|||
|
||||
if (irc.connection.registered === false) {
|
||||
const nickLen = parseInt(network.irc.network.options.NICKLEN, 10) || 16;
|
||||
|
||||
const random = (data.nick || irc.user.nick) + Math.floor(Math.random() * 10);
|
||||
|
||||
// Safeguard nick changes up to allowed length
|
||||
// Some servers may send "nick in use" error even for randomly generated nicks
|
||||
if (random.length <= nickLen) {
|
||||
// Only change the IRC session nick (irc.user.nick), not the user's preference (network.nick)
|
||||
// This allows the quit handler to reclaim the preferred nick when it becomes available
|
||||
irc.changeNick(random);
|
||||
}
|
||||
}
|
||||
|
||||
client.emit("nick", {
|
||||
network: network.uuid,
|
||||
nick: irc.user.nick,
|
||||
});
|
||||
});
|
||||
|
||||
irc.on("nick invalid", function (data) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,19 @@ export default <IrcEventHandler>function (irc, network) {
|
|||
const client = this;
|
||||
|
||||
irc.on("registered", function (data) {
|
||||
network.setNick(data.nick);
|
||||
// Only update the user's preferred nick (network.nick) if we registered with it
|
||||
// If we registered with a fallback nick (e.g., nick123), don't overwrite the preference
|
||||
// This allows the existing quit handler to reclaim the preferred nick when available
|
||||
if (data.nick === network.nick) {
|
||||
// We got our preferred nick, clear keepNick if it was set
|
||||
if (network.keepNick === data.nick) {
|
||||
network.keepNick = null;
|
||||
}
|
||||
} else if (data.nick !== network.nick) {
|
||||
// We registered with a fallback, don't call setNick which would overwrite the preference
|
||||
// Just update the IRC session nick
|
||||
irc.user.nick = data.nick;
|
||||
}
|
||||
|
||||
const lobby = network.getLobby();
|
||||
const msg = new Msg({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue