diff --git a/client/js/lounge.js b/client/js/lounge.js index 1b65f4b0..914d9c2c 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -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) { diff --git a/src/client.js b/src/client.js index 222b7628..f8be844a 100644 --- a/src/client.js +++ b/src/client.js @@ -42,6 +42,7 @@ var inputs = [ "invite", "kick", "mode", + "nick", "notice", "query", "quit", diff --git a/src/plugins/inputs/nick.js b/src/plugins/inputs/nick.js new file mode 100644 index 00000000..a267b1e4 --- /dev/null +++ b/src/plugins/inputs/nick.js @@ -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 " + })); + 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 + }); + } +};