Anton Shestakov <av6@dwimlabs.net>, Wed, 23 Mar 2016 16:55:52 +0800
index: maintain only one contact with type 'self'
This isn't done in an event handler of contacts collection because doing it in
'add' handler would trigger 'sort' event after the model has been added, but
before its 'add' event has propagated, and that's dumb.
coffee/xmpp.coffee
Permissions: -rw-r--r--
console.debug('connection exists, not reconnecting') @conn = new Strophe.Connection("https://#{ Tram.config.host }/http-bind") jid = "#{ node }@#{ Tram.config.domain }" @conn.connect(jid, pass, @onConnect) @conn.register.connect(Tram.config.domain, @onConnect) register: (username, password) -> @conn.register.fields.username = username @conn.register.fields.password = password savevCard: (data, okcb, failcb) -> $vcard = $iq(type: 'set').c('vCard', xmlns: Strophe.NS.VCARD) $vcard.c('NICKNAME').t(data.nickname).up() $vcard.c('FN').t(data.fullname).up() bi = data.avatar.indexOf(b) type = data.avatar.substr(dl, bi - dl) binval = data.avatar.substr(bi + bl) @conn.sendIQ($vcard.tree(), okcb, failcb) onConnect: (status, error) => when Strophe.Status.CONNECTING console.debug('Strophe is connecting.') when Strophe.Status.AUTHENTICATING console.debug('Strophe is authenticating.') @trigger('authenticating') when Strophe.Status.AUTHFAIL console.debug('Strophe failed to authenticate:', error) when Strophe.Status.ERROR console.debug('Strophe received an error:', error) when Strophe.Status.CONNFAIL console.debug('Strophe failed to connect:', error) when Strophe.Status.DISCONNECTING console.debug('Strophe is disconnecting.') @trigger('disconnecting') when Strophe.Status.DISCONNECTED console.debug('Strophe is disconnected.') when Strophe.Status.CONNECTED console.debug('Strophe is connected.') console.info('My jid:', @conn.jid) when Strophe.Status.ATTACHED console.debug('Strophe is attached.') console.info('My jid:', @conn.jid) when Strophe.Status.REGISTER console.debug('Got registration prompt.') when Strophe.Status.REGISTERED console.debug('Registered!') when Strophe.Status.CONFLICT console.debug('Contact already exists!') when Strophe.Status.NOTACCEPTABLE console.debug('Registration form not properly filled out.') @trigger('notacceptable') when Strophe.Status.REGIFAIL console.debug('The server does not support In-Band Registration.') _(Tram.XMPPInterface.prototype).extend(Backbone.Events)