Browse files

Warn users when a new one joins

  • Loading branch information...
1 parent e7c4704 commit 069cf6f4fd7b579c9a728b0774b67aba57fcae37 @reu committed Dec 26, 2010
Showing with 10 additions and 3 deletions.
  1. +9 −2 app.js
  2. +1 −1 views/partials/message.jade
View
11 app.js
@@ -149,8 +149,15 @@ app.get('/rooms/:room_id', filters.getRoom, filters.getUser, function(req, res){
});
app.get('/rooms/:room_id/join', filters.getRoom, function(req, res){
- if (!req.room.users[req.sessionID])
- req.room.users[req.sessionID] = new User(req.query.user.nick);
+ if (!req.room.users[req.sessionID]) {
+ var user = new User(req.query.user.nick);
+ req.room.users[req.sessionID] = user;
+
+ // Alert people that a new user joined the room
+ var message = new Message(req.room.name, user.nick + ' joined!');
+ message.type = 'notice';
+ req.room.appendMessage(message);
+ }
res.redirect('/rooms/' + req.room.id);
});
View
2 views/partials/message.jade
@@ -1,4 +1,4 @@
-tr.message(data-time: message.sent_at)
+tr.message(data-time: message.sent_at, class: message.type)
td!= message.from
td!= new Date(message.sent_at)
td!= message.text

0 comments on commit 069cf6f

Please sign in to comment.