Skip to content

Commit

Permalink
Allow nick change
Browse files Browse the repository at this point in the history
Added simple nick change functionality on frontend and backend.
Doesn't account for when the new nick is taken.
  • Loading branch information
johsoe authored and cwc committed Jun 6, 2012
1 parent fa65db2 commit f75c1ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions assets/js/client.js
Expand Up @@ -210,13 +210,17 @@ $(function() {
if (data.oldNick === irc.me.get('nick'))
irc.me.set('nick', data.newNick);

// TODO: If not me, change name in user list and send channel message
var channel = irc.chatWindows.getByName(data.channels[0]);
var user = channel.userList.getByNick(data.oldNick);
user.set({nick: data.newNick});
user.view.render();

// Add nickmessage to all channels
var nickMessage = new Message({type: 'nick', oldNick: data.oldNick, newNick: data.newNick});
channel.stream.add(nickMessage);
for( var i in data.channels ) {
channel = irc.chatWindows.getByName(data.channels[i]);
channel.stream.add(nickMessage);
}
});

irc.socket.on('topic', function(data) {
Expand Down Expand Up @@ -300,6 +304,12 @@ $(function() {
irc.appView.channelList.channelTabs[0].setActive();
}
break;

case '/nick':
if (commandText[1]) {
irc.socket.emit('nick', {nick : commandText[1]});
}
break;
case '/topic':
if (commandText[2]) {
irc.socket.emit('topic', {name: commandText[1], topic: commandText[2]});
Expand Down
6 changes: 6 additions & 0 deletions lib/irchandler.js
Expand Up @@ -207,6 +207,12 @@ var irchandler = exports.irchandler = function(socket, app) {
client.send('TOPIC ' + data.name + ' ' + data.topic);
});

socket.on('nick', function(data){
client.send('NICK ' + data.nick);
client.nick = data.nick;
client.opt.nick = data.nick;
});

socket.on('command', function(text) { console.log(text); client.send(text); });

socket.on('disconnect', function() {
Expand Down

0 comments on commit f75c1ac

Please sign in to comment.