Skip to content

Commit

Permalink
Merge pull request #49 from thedjpetersen/42/feature/quits
Browse files Browse the repository at this point in the history
Support for quits on channels
  • Loading branch information
thedjpetersen committed Feb 2, 2012
2 parents 2ef1cdf + 5bae8df commit 70fcdae
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
16 changes: 15 additions & 1 deletion assets/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $(function() {
//irc.chatWindows.getByName('status').stream.add({sender: 'notice', raw: data.text, type: 'notice'});
});

irc.socket.on('nick', function(data) {
irc.socket.on('getNick', function(data) {
irc.me.nick = data.nick;
});

Expand Down Expand Up @@ -109,6 +109,20 @@ $(function() {
}
});

irc.socket.on('quit', function(data) {
var channel, user, quitMessage;
for(var i=0; i<data.channels.length; i++){
channel = irc.chatWindows.getByName(data.channels[i]);
if(channel !== undefined) {
user = channel.userList.getByNick(data.nick);
user.view.remove();
user.destroy();
quitMessage = new Message({type: 'quit', nick: data.nick, reason: data.reason, message: data.message});
channel.stream.add(quitMessage);
}
}
});

irc.socket.on('names', function(data) {
var channel = irc.chatWindows.getByName(data.channel);
channel.userList = new UserList(channel);
Expand Down
4 changes: 2 additions & 2 deletions assets/js/views/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ var ChatView = Backbone.View.extend({

$chatWindow.append(view.el);

if (sender === irc.me.nick && ['join', 'part'].indexOf(type) === -1) {
if (sender === irc.me.nick && 'message'.indexOf(type) === 0) {
$(view.el).addClass('message-me');
}

if(['join', 'part', 'topic'].indexOf(type) !== -1){
if(['join', 'part', 'topic', 'quit'].indexOf(type) !== -1){
$(view.el).addClass('message_notification');
}

Expand Down
11 changes: 10 additions & 1 deletion assets/js/views/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var MessageView = Backbone.View.extend({
var nick = this.model.get('sender') || this.model.collection.channel.get('name');
var html;

if (_.include(['join', 'part', 'nick', 'topic'], this.model.get('type')))
if (_.include(['join', 'part', 'nick', 'topic', 'quit'], this.model.get('type')))
html = this.setText(this.model.get('type'));
// This handles whether to output a message or an action
else if (this.model.get('text').substr(1, 6) === 'ACTION') {
Expand Down Expand Up @@ -46,6 +46,15 @@ var MessageView = Backbone.View.extend({
action: type === 'join' ? 'joined' : 'left'
});
break;
case 'quit':
html = ich.join_part({
type: 'part',
nick: this.model.get('nick'),
action: 'left',
reason: '(' + this.model.get('reason') + ')',
message: '(' + this.model.get('message') + ')'
});
break
case 'nick':
html = ich.nick({
oldNick: this.model.get('oldNick'),
Expand Down
3 changes: 2 additions & 1 deletion lib/irchandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var irchandler = exports.irchandler = function(socket) {
var events = {
'join': ['channel', 'nick'],
'part': ['channel', 'nick'],
'quit': ['nick', 'reason', 'channels', 'message'],
'topic': ['channel', 'topic', 'nick'],
'nick': ['oldNick', 'newNick', 'channels'],
'names': ['channel', 'nicks'],
Expand Down Expand Up @@ -38,7 +39,7 @@ var irchandler = exports.irchandler = function(socket) {
});

socket.on('getNick', function(data) {
socket.emit('nick', {nick: client.nick});
socket.emit('getNick', {nick: client.nick});
});

socket.on('command', function(text) { console.log(text); client.send(text); });
Expand Down
2 changes: 1 addition & 1 deletion views/templates.jade
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ script(id="message", type="text/html")

script(id="join_part", type="text/html")
span(class="{{type}}_img")
span <b>{{nick}}</b> {{action}} the channel
span <b>{{nick}}</b> {{action}} the channel {{reason}} {{message}}

script(id="nick", type="text/html")
span <b>{{oldNick}}</b> is now known as {{newNick}}

0 comments on commit 70fcdae

Please sign in to comment.