summaryrefslogtreecommitdiff
path: root/public/js/lib/views/room/userlist.js
blob: 0157cad7146724fdee04eacd07a2fe4ed008b4be (plain)
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
var UserlistView = View.extend({
  
  el: "#userlist",
  
  events: {
  },
  
  users: {},
  initialize: function(){
    var base = this
    app.socket.on("joins", function(data){
      base.users[data.nick] = true
      base.update()
    })
    app.socket.on("parts", function(data){
      delete base.users[data.nick]
      base.update()
    })
  },
  
  update: function(users){
    if (users) { this.users = users }
    var base = this
    this.$el.empty()
    Object.keys(base.users).sort().forEach(function(nick){
      var el = document.createElement("div")
      el.innerHTML = nick
      base.el.appendChild(el)
    })
  },
  
})