Implement our own /nick command to allow editing nick when not connected

This commit is contained in:
Pavel Djundik 2016-10-01 20:04:03 +03:00 committed by Jérémie Astori
parent beb6d1ea5b
commit 024369d4c3
3 changed files with 48 additions and 5 deletions

View file

@ -734,16 +734,20 @@ $(function() {
$("#nick-value").attr("contenteditable", toggle);
}
// FIXME Reset content when new nick is invalid (already in use, forbidden chars, ...)
function submitNick() {
var newNick = $("#nick-value").text();
var newNick = $("#nick-value").text().trim();
if (newNick.length === 0) {
cancelNick();
return;
}
toggleNickEditor(false);
socket.emit("input", {
target: chat.data("id"),
text: "/nick " + newNick
});
toggleNickEditor(false);
}
function cancelNick() {
@ -1253,10 +1257,11 @@ $(function() {
}
function setNick(nick) {
$("#nick-value").text(nick);
// Closes the nick editor when canceling, changing channel, or when a nick
// is set in a different tab / browser / device.
toggleNickEditor(false);
$("#nick-value").text(nick);
}
function move(array, old_index, new_index) {

View file

@ -42,6 +42,7 @@ var inputs = [
"invite",
"kick",
"mode",
"nick",
"notice",
"query",
"quit",

View file

@ -0,0 +1,37 @@
var Msg = require("../../models/msg");
exports.commands = ["nick"];
exports.allowDisconnected = true;
exports.input = function(network, chan, cmd, args) {
if (args.length === 0) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: "Usage: /nick <your new nick>"
}));
return;
}
if (args.length !== 1) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: "Nicknames may not contain spaces."
}));
return;
}
var newNick = args[0];
// If connected to IRC, send to server and wait for ACK
// otherwise update the nick and UI straight away
if (network.irc && network.irc.connection) {
network.irc.raw("NICK", newNick);
} else {
network.setNick(newNick);
this.emit("nick", {
network: network.id,
nick: newNick
});
}
};