app/assets/javascripts/backbone/models/chat.js.coffee
6a6ccd01
 class Xmpp.Models.Chat extends Xmpp.Models.Model
   namespace: 'app.chat'
 
   defaults:
     who: null
     withWhom: null
2a61cdcc
     chatId: null
94bd8368
     isMultiChat: false
6a6ccd01
 
   initialize: ->
     _.bindAll(this)
 
94bd8368
     if (@get('isMultiChat'))
       @set('withWhom', [])
 
31111b63
     #App.Com.openNewMultiChatId(@get('who').get('jid'), @get('withWhom').get('jid'), this)
2a61cdcc
 
94bd8368
   appendWithWhom: (newPerson) ->
     allWithWhom = @get('withWhom');
 
     exists = _.find(allWithWhom, (withWhom) ->
       withWhom == newPerson
     )?
 
     if not exists
       allWithWhom.push(newPerson)
 
2a61cdcc
   setChatId: (id) ->
94bd8368
     App.debug ['multichat has id', id]
2a61cdcc
     @set('chatId', id)
 
c6c526f1
   syncContacts: (contacts, owner) ->
     contactsWithoutMe = _.filter(contacts, (jid) ->
       jid != App.Models.me.get('jid')
     )
 
eb420b38
     if (owner != App.Models.me.get('jid'))
       contactsWithoutMe = contactsWithoutMe.concat([owner]);
 
c6c526f1
     attendants = _.map(contactsWithoutMe, (jid) =>
       contact = App.Collections.contacts.findByJid(jid)
       if not contact
         newTempContact = @createTempContact(jid)
         App.Collections.contacts.add(newTempContact)
         contact = newTempContact
 
       contact
     )
 
     @set('withWhom', attendants);
 
     if owner
       ownerContact = App.Collections.contacts.findByJid(owner)
       if not ownerContact
         ownerContact = @createTempContact(owner)
         App.Collections.contacts.add(ownerContact)
 
       @set('who', ownerContact)
 
     App.debug ['importing contacts to chat', this]
 
 
6a6ccd01
 class Xmpp.Collections.ChatsCollection extends Backbone.Collection
   model: Xmpp.Models.Chat
 
   initialize: ->
     _.bindAll(this)
 
bcce524b
     Backbone.Events.on('closeChat', (tab, chat) =>
       @removeChat(chat)
     )
6a6ccd01
 
   find: (who, withWhom) ->
fcce5d56
     _.find(@models, (chat) ->
6a6ccd01
       chat.get('who') == who && chat.get('withWhom') == withWhom
     )
 
1f685c13
   findById: (id) ->
     @findWhere(chatId: id)
 
6a6ccd01
   removeChat: (chat) ->
c6c526f1
     @models = _.without(@openedChats, chat)
 
   createTempContact: (jid) ->
     newTempContact = new Xmpp.Models.Contact(jid: jid, belongsTo: [App.Models.me])
     newTempContact