-
Notifications
You must be signed in to change notification settings - Fork 0
/
chennairb.coffee
35 lines (26 loc) · 856 Bytes
/
chennairb.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@Rooms = new Mongo.Collection "rooms"
@Messages = new Mongo.Collection "messages"
if Meteor.isClient
Session.setDefault "activeRoom", "Ruby"
Template.main.helpers
rooms: ->
Rooms.find()
Template.main.events
"click .room-name":(e) ->
Session.set "activeRoom", @name
Template.room.helpers
activeRoom: ->
Session.get "activeRoom"
messages: ->
Messages.find({room: Session.get "activeRoom"})
Template.room.events
"keypress #message":(e,t) ->
message = t.$('#message').val().trim()
username = if Meteor.user() then Meteor.user().profile.name else "Anonymous dude"
if e.which is 13 and message isnt ""
Messages.insert
message: message
username: username
room: Session.get "activeRoom"
time: Date.now()
t.$('#message').val('')