Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

show participants list

  • Loading branch information...
commit 6f665667899a1d47567af251c1f9a2824d0867f4 1 parent ff13f20
Adam Bachman authored
32  app/assets/javascripts/rooms.coffee
@@ -2,19 +2,32 @@ class Derp.Room
2 2
   constructor: (@room, @user) ->
3 3
     @ws = new WebSocket "ws://#{ SOCKET_HOST }/#{@room}/#{@user}"
4 4
 
5  
-    @ws.onmessage = (e) =>
6  
-      data = JSON.parse(e.data)
  5
+    @ws.onmessage = (evt) =>
  6
+      data = JSON.parse(evt.data)
  7
+
  8
+      if data['user'] == 'system'
  9
+        userClass = 'system'
  10
+        console.dir data
  11
+        @setParticipants(data['members'])
  12
+      else
  13
+        userClass = if data['user'] == @user
  14
+                      'myself'
  15
+                    else
  16
+                      ''
  17
+
7 18
       comments = $('#comments')
8 19
 
9 20
       comments.append """
10 21
         <div class='message'>
11  
-          <div class='username #{if (data['user'] == @user) then 'myself' else '' }'>#{data['user']}</div>
  22
+          <div class='username #{userClass}'>#{data['user']}</div>
12 23
           <div class='comment'>#{data['comment']}</div>
13 24
         </div>
14 25
       """
15 26
 
16 27
     @ws.onclose = => @setStatus('disconnected')
17  
-    @ws.onopen = => @setStatus('connected')
  28
+
  29
+    @ws.onopen = (evt) =>
  30
+      @setStatus('connected')
18 31
 
19 32
   sendMessage: ->
20 33
     @ws.send $('#comment').val()
@@ -22,3 +35,14 @@ class Derp.Room
22 35
 
23 36
   setStatus: (str) ->
24 37
     $('#msg').text str
  38
+    if str == 'connected'
  39
+      $('#msg').css color: '#0a0'
  40
+    else if str == 'disconnected'
  41
+      $('#msg').css color: '#a00'
  42
+
  43
+  setParticipants: (list) ->
  44
+
  45
+    $('ul.participants').empty()
  46
+    for p in _(list).values()
  47
+      $('ul.participants').append("<li>#{p}</li>")
  48
+
13  app/assets/stylesheets/rooms.css.less
@@ -12,8 +12,21 @@
12 12
     &.myself {
13 13
       color: @green;
14 14
     }
  15
+    &.system {
  16
+      color: @orange;
  17
+    }
15 18
   }
16 19
   .comment {
17 20
     .makeColumn(6);
18 21
   }
19 22
 }
  23
+
  24
+.room-heading {
  25
+  margin-bottom: 32px;
  26
+}
  27
+
  28
+#comment_form {
  29
+  #msg {
  30
+    padding-left: 18px;
  31
+  }
  32
+}
19  app/views/rooms/show.html.haml
@@ -6,12 +6,23 @@
6 6
 .container
7 7
   .row
8 8
     .span8.offset2
9  
-      %h2= @room
  9
+      %h2.room-heading
  10
+        %small room
  11
+        = @room
  12
+
  13
+  .row
  14
+    .span2
  15
+      %strong participants
  16
+      %ul.participants.unstyled
  17
+
  18
+    .span8
  19
+      %table.table.table-condensed#comments
  20
+
  21
+  .row
  22
+    .span8.offset2
10 23
       %div#form
11 24
         %form.form-inline#comment_form{:onsubmit => 'room.sendMessage(); return false'}
12 25
           %input.span4#comment{:type=>'text'}
13 26
           %input#submit.btn.info{:type=>'button', :value=>'send', :onclick=>'room.sendMessage();'}
14  
-        %span#msg
15  
-
16  
-      %table.table.table-condensed#comments
  27
+          %span#msg
17 28
 

0 notes on commit 6f66566

Please sign in to comment.
Something went wrong with that request. Please try again.