Permalink
Browse files

Inform when a user leaves the room

  • Loading branch information...
1 parent 069cf6f commit 575e309b6ea598cb9894d5531d8d329b20893d9d @reu committed Dec 26, 2010
Showing with 17 additions and 0 deletions.
  1. +13 −0 app.js
  2. +4 −0 public/javascripts/pool.js
View
13 app.js
@@ -162,6 +162,19 @@ app.get('/rooms/:room_id/join', filters.getRoom, function(req, res){
res.redirect('/rooms/' + req.room.id);
});
+app.get('/rooms/:room_id/leave', filters.getRoom, filters.getUser, function(req, res){
+ if (delete req.room.users[req.sessionID]) {
+ req.session.destroy();
+
+ var message = new Message(req.room.name, req.user.nick + ' left the room.');
+ message.type = 'notice';
+ req.room.appendMessage(message);
+ }
+
+ res.writeHead(200);
+ res.end();
+});
+
// Messages
// List
app.get('/rooms/:room_id/messages', filters.getRoom, function(req, res){
@@ -70,4 +70,8 @@ jQuery(function($){
else
$('title').html('xpress chat');
}
+
+ $(window).unload(function() {
+ $.get('/rooms/' + $('#room').data('room-id') + '/leave', null, null, 'json');
+ });
});

0 comments on commit 575e309

Please sign in to comment.