Implement keep nick
This commit is contained in:
parent
c4236e0e12
commit
600115b8d1
@ -19,6 +19,7 @@ const filteredFromClient = {
|
|||||||
irc: true,
|
irc: true,
|
||||||
password: true,
|
password: true,
|
||||||
ignoreList: true,
|
ignoreList: true,
|
||||||
|
keepNick: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
function Network(attr) {
|
function Network(attr) {
|
||||||
@ -43,6 +44,7 @@ function Network(attr) {
|
|||||||
},
|
},
|
||||||
chanCache: [],
|
chanCache: [],
|
||||||
ignoreList: [],
|
ignoreList: [],
|
||||||
|
keepNick: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!this.uuid) {
|
if (!this.uuid) {
|
||||||
@ -188,6 +190,7 @@ Network.prototype.edit = function(client, args) {
|
|||||||
const oldNick = this.nick;
|
const oldNick = this.nick;
|
||||||
const oldRealname = this.realname;
|
const oldRealname = this.realname;
|
||||||
|
|
||||||
|
this.keepNick = null;
|
||||||
this.nick = args.nick;
|
this.nick = args.nick;
|
||||||
this.host = String(args.host || "");
|
this.host = String(args.host || "");
|
||||||
this.name = String(args.name || "") || this.host;
|
this.name = String(args.name || "") || this.host;
|
||||||
@ -217,7 +220,7 @@ Network.prototype.edit = function(client, args) {
|
|||||||
if (this.nick !== oldNick) {
|
if (this.nick !== oldNick) {
|
||||||
if (connected) {
|
if (connected) {
|
||||||
// Send new nick straight away
|
// Send new nick straight away
|
||||||
this.irc.raw("NICK", this.nick);
|
this.irc.changeNick(this.nick);
|
||||||
} else {
|
} else {
|
||||||
this.irc.options.nick = this.irc.user.nick = this.nick;
|
this.irc.options.nick = this.irc.user.nick = this.nick;
|
||||||
|
|
||||||
@ -269,6 +272,10 @@ Network.prototype.setNick = function(nick) {
|
|||||||
// Case insensitive search
|
// Case insensitive search
|
||||||
"i"
|
"i"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.keepNick === nick) {
|
||||||
|
this.keepNick = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,16 +41,27 @@ exports.input = function(network, chan, cmd, args) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we were trying to keep a nick and user changes nick, stop trying to keep the old one
|
||||||
|
network.keepNick = null;
|
||||||
|
|
||||||
// If connected to IRC, send to server and wait for ACK
|
// If connected to IRC, send to server and wait for ACK
|
||||||
// otherwise update the nick and UI straight away
|
// otherwise update the nick and UI straight away
|
||||||
if (network.irc && network.irc.connection) {
|
if (network.irc) {
|
||||||
network.irc.raw("NICK", newNick);
|
if (network.irc.connection && network.irc.connection.connected) {
|
||||||
} else {
|
network.irc.changeNick(newNick);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
network.irc.options.nick = network.irc.user.nick = newNick;
|
||||||
|
}
|
||||||
|
|
||||||
network.setNick(newNick);
|
network.setNick(newNick);
|
||||||
|
|
||||||
this.emit("nick", {
|
this.emit("nick", {
|
||||||
network: network.uuid,
|
network: network.uuid,
|
||||||
nick: newNick,
|
nick: newNick,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
this.save();
|
||||||
};
|
};
|
||||||
|
@ -124,6 +124,19 @@ module.exports = function(irc, network) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (network.keepNick) {
|
||||||
|
// We disconnected without getting our original nick back yet, just set it back locally
|
||||||
|
irc.options.nick = irc.user.nick = network.keepNick;
|
||||||
|
|
||||||
|
network.setNick(network.keepNick);
|
||||||
|
network.keepNick = null;
|
||||||
|
|
||||||
|
this.emit("nick", {
|
||||||
|
network: network.uuid,
|
||||||
|
nick: network.nick,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
sendStatus();
|
sendStatus();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -44,10 +44,22 @@ module.exports = function(irc, network) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
irc.on("nick in use", function(data) {
|
irc.on("nick in use", function(data) {
|
||||||
|
let message = data.nick + ": " + (data.reason || "Nickname is already in use.");
|
||||||
|
|
||||||
|
if (irc.connection.registered === false && !Helper.config.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;
|
||||||
|
}
|
||||||
|
|
||||||
const lobby = network.channels[0];
|
const lobby = network.channels[0];
|
||||||
const msg = new Msg({
|
const msg = new Msg({
|
||||||
type: Msg.Type.ERROR,
|
type: Msg.Type.ERROR,
|
||||||
text: data.nick + ": " + (data.reason || "Nickname is already in use."),
|
text: message,
|
||||||
showInActive: true,
|
showInActive: true,
|
||||||
});
|
});
|
||||||
lobby.pushMessage(client, msg, true);
|
lobby.pushMessage(client, msg, true);
|
||||||
|
@ -27,5 +27,11 @@ module.exports = function(irc, network) {
|
|||||||
chan: chan.id,
|
chan: chan.id,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If user with the nick we are trying to keep has quit, try to get this nick
|
||||||
|
if (network.keepNick === data.nick) {
|
||||||
|
irc.changeNick(network.keepNick);
|
||||||
|
network.keepNick = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user