app/assets/javascripts/backbone/models/contact.js.coffee
ff94bdbf
 class Xmpp.Models.Contact extends Xmpp.Models.Model
   namespace: 'app.roster'
 
   defaults:
52ef7688
     jid: ''
     name: ''
     status: 'offline'
     message: ''
4b5bb9c5
     avatar: ''
6a6ccd01
     belongsTo: ''
ff94bdbf
 
   initialize: ->
b27f285a
     _.bindAll(this)
ff94bdbf
 
52ef7688
     if ! @get('name')
       @set(name: @get('jid'))
 
6a6ccd01
   firstname: ->
     @get('name').split(' ')[0]
52ef7688
 
ff94bdbf
 class Xmpp.Collections.ContactsCollection extends Backbone.Collection
   model: Xmpp.Models.Contact
b27f285a
 
   initialize: ->
     _.bindAll(this)
e2e90aca
 
b27f285a
     @friendsList = new Xmpp.Views.Contacts.ListView(collection: this, attributes: {title: 'chat.roster.friends', id: 'js-inactive-friends'})
e2e90aca
     @friendsList.createListContainer()
 
     @activeList  = new Xmpp.Views.Contacts.ListView(collection: this, attributes: {title: 'chat.roster.chat-group', id: 'js-active-friends'})
     @activeList.setAsActiveChatGroup()
b27f285a
 
     @on("add", @appendContact)
 
   appendContact: (contact) ->
52ef7688
     @friendsList.appendContact(contact)
 
e2e90aca
   moveToActiveList: (contact) ->
     @_switchContactBelongingList(@get(contact), @friendsList, @activeList)
 
   moveToInactiveList: (contact) ->
     if contact == 'all'
       _.each(@activeList.contactViews, (view) =>
         @_switchContactBelongingList(view.model, @activeList, @friendsList)
       )
     else
       @_switchContactBelongingList(@get(contact), @activeList, @friendsList)
 
52ef7688
   updateStatus: (response) ->
     @get(response.jid).set(message: response.status.message, status: response.status.status)
 
   udpateVcard: (response) ->
e2e90aca
     @get(response.jid).set(name: response.vcard.name, avatar: response.vcard.avatar)
 
   _switchContactBelongingList: (contact, fromList, toList) ->
     if !contact?
       false
 
     fromList.detachContact(contact) && toList.appendContact(contact)
 
     true