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

View File

@ -42,6 +42,7 @@ var inputs = [
"invite", "invite",
"kick", "kick",
"mode", "mode",
"nick",
"notice", "notice",
"query", "query",
"quit", "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
});
}
};