112:f4a4878c99a3
Anton Shestakov <av6@dwimlabs.net>, Thu, 07 Apr 2016 22:56:16 +0800
index: check if roster has the item before removing it Sometimes we get events from contacts that are not in user's roster, trying to remove such contacts used to fail before this patch.

next change 117:477f7f7cce15
previous change 22:dba8124befc3

js/xmpp.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.10.0
(function() {
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Tram.XMPPInterface = (function() {
XMPPInterface.prototype.conn = null;
function XMPPInterface() {
this.onConnect = bind(this.onConnect, this);
}
XMPPInterface.prototype._prepareConnection = function() {
if (this.conn != null) {
console.debug('connection exists, not reconnecting');
}
return this.conn = new Strophe.Connection("https://" + Tram.config.host + "/http-bind");
};
XMPPInterface.prototype.connect = function(node, pass) {
var jid;
this._prepareConnection();
jid = node + "@" + Tram.config.domain;
return this.conn.connect(jid, pass, this.onConnect);
};
XMPPInterface.prototype.disconnect = function(reason) {
if (this.conn == null) {
return;
}
this.conn.disconnect(reason);
this.conn = null;
};
XMPPInterface.prototype.startRegistration = function() {
this._prepareConnection();
return this.conn.register.connect(Tram.config.domain, this.onConnect);
};
XMPPInterface.prototype.register = function(username, password) {
this.conn.register.fields.username = username;
this.conn.register.fields.password = password;
return this.conn.register.submit();
};
XMPPInterface.prototype.finishRegistration = function() {
return this.conn.authenticate();
};
XMPPInterface.prototype.savevCard = function(data, okcb, failcb) {
var $vcard, b, bi, binval, bl, d, dl, type;
$vcard = $iq({
type: 'set'
}).c('vCard', {
xmlns: Strophe.NS.VCARD
});
if (data.nickname) {
$vcard.c('NICKNAME').t(data.nickname).up();
}
if (data.fullname) {
$vcard.c('FN').t(data.fullname).up();
}
if (data.avatar) {
b = ';base64,';
d = 'data:';
dl = d.length;
bl = b.length;
bi = data.avatar.indexOf(b);
type = data.avatar.substr(dl, bi - dl);
binval = data.avatar.substr(bi + bl);
$vcard.c('PHOTO').c('TYPE').t(type).up().c('BINVAL').t(binval);
}
return this.conn.sendIQ($vcard.tree(), okcb, failcb);
};
XMPPInterface.prototype.onConnect = function(status, error) {
switch (status) {
case Strophe.Status.CONNECTING:
console.debug('Strophe is connecting.');
return this.trigger('connecting');
case Strophe.Status.AUTHENTICATING:
console.debug('Strophe is authenticating.');
return this.trigger('authenticating');
case Strophe.Status.AUTHFAIL:
console.debug('Strophe failed to authenticate:', error);
return this.trigger('authfail');
case Strophe.Status.ERROR:
console.debug('Strophe received an error:', error);
return this.trigger('error');
case Strophe.Status.CONNFAIL:
console.debug('Strophe failed to connect:', error);
return this.trigger('connfail');
case Strophe.Status.DISCONNECTING:
console.debug('Strophe is disconnecting.');
return this.trigger('disconnecting');
case Strophe.Status.DISCONNECTED:
console.debug('Strophe is disconnected.');
return this.trigger('disconnected');
case Strophe.Status.CONNECTED:
console.debug('Strophe is connected.');
console.info('My jid:', this.conn.jid);
return this.trigger('connected');
case Strophe.Status.ATTACHED:
console.debug('Strophe is attached.');
console.info('My jid:', this.conn.jid);
return this.trigger('attached');
case Strophe.Status.REGISTER:
console.debug('Got registration prompt.');
return this.trigger('register');
case Strophe.Status.REGISTERED:
console.debug('Registered!');
return this.trigger('registered');
case Strophe.Status.CONFLICT:
console.debug('Contact already exists!');
return this.trigger('conflict');
case Strophe.Status.NOTACCEPTABLE:
console.debug('Registration form not properly filled out.');
return this.trigger('notacceptable');
case Strophe.Status.REGIFAIL:
console.debug('The server does not support In-Band Registration.');
return this.trigger('regifail');
}
};
return XMPPInterface;
})();
_(Tram.XMPPInterface.prototype).extend(Backbone.Events);
}).call(this);
//# sourceMappingURL=xmpp.js.map