web/lib/javascripts/session.js in vines-0.2.1 vs web/lib/javascripts/session.js in vines-0.3.0
- old
+ new
@@ -12,11 +12,11 @@
};
}
Session.prototype.connect = function(jid, password, callback) {
return this.xmpp.connect(jid, password, __bind(function(status) {
switch (status) {
- case Strophe.Status.CONNFAIL:
+ case Strophe.Status.AUTHFAIL || Strophe.Status.CONNFAIL:
return callback(false);
case Strophe.Status.CONNECTED:
this.xmpp.addHandler((__bind(function(el) {
return this.handleIq(el);
}, this)), null, 'iq');
@@ -27,11 +27,11 @@
return this.handlePresence(el);
}, this)), null, 'presence');
callback(true);
return this.findRoster(__bind(function() {
this.notify('roster');
- this.xmpp.send($('<presence/>').get(0));
+ this.xmpp.send(this.xml('<presence/>'));
return this.findCards();
}, this));
}
}, this));
};
@@ -137,12 +137,12 @@
return new Contact(this);
}).get();
};
Session.prototype.findRoster = function(callback) {
var node;
- node = $("<iq id='" + (this.uniqueId()) + "' type=\"get\">\n <query xmlns=\"jabber:iq:roster\"/>\n</iq>");
- return this.sendIQ(node.get(0), __bind(function(result) {
+ node = this.xml("<iq id='" + (this.uniqueId()) + "' type=\"get\">\n <query xmlns=\"jabber:iq:roster\"/>\n</iq>");
+ return this.sendIQ(node, __bind(function(result) {
var contact, contacts, _i, _len;
contacts = this.parseRoster(result);
for (_i = 0, _len = contacts.length; _i < _len; _i++) {
contact = contacts[_i];
this.roster[contact.jid] = contact;
@@ -156,44 +156,44 @@
$('body', node).text(message);
return this.xmpp.send(node);
};
Session.prototype.sendPresence = function(away, status) {
var node;
- node = $('<presence/>');
+ node = $(this.xml('<presence/>'));
if (away) {
- node.append($('<show>xa</show>'));
+ node.append($(this.xml('<show>xa</show>')));
if (status !== 'Away') {
- node.append($('<status/>').text(status));
+ node.append($(this.xml('<status/>')).text(status));
}
} else {
if (status !== 'Available') {
- node.append($('<status/>').text(status));
+ node.append($(this.xml('<status/>')).text(status));
}
}
- return this.xmpp.send(node.get(0));
+ return this.xmpp.send(node);
};
Session.prototype.sendIQ = function(node, callback) {
return this.xmpp.sendIQ(node, callback, callback, 5000);
};
Session.prototype.updateContact = function(contact, add) {
var group, node, _i, _len, _ref;
- node = $("<iq id=\"" + (this.uniqueId()) + "\" type=\"set\">\n <query xmlns=\"jabber:iq:roster\">\n <item name=\"\" jid=\"" + contact.jid + "\"/>\n </query>\n</iq>");
+ node = this.xml("<iq id=\"" + (this.uniqueId()) + "\" type=\"set\">\n <query xmlns=\"jabber:iq:roster\">\n <item name=\"\" jid=\"" + contact.jid + "\"/>\n </query>\n</iq>");
$('item', node).attr('name', contact.name);
_ref = contact.groups;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
group = _ref[_i];
- $('item', node).append($('<group></group>').text(group));
+ $('item', node).append($(this.xml('<group></group>')).text(group));
}
- this.xmpp.send(node.get(0));
+ this.xmpp.send(node);
if (add) {
return this.sendSubscribe(contact.jid);
}
};
Session.prototype.removeContact = function(jid) {
var node;
- node = $("<iq id=\"" + (this.uniqueId()) + "\" type=\"set\">\n <query xmlns=\"jabber:iq:roster\">\n <item jid=\"" + jid + "\" subscription=\"remove\"/>\n </query>\n</iq>");
- return this.xmpp.send(node.get(0));
+ node = this.xml("<iq id=\"" + (this.uniqueId()) + "\" type=\"set\">\n <query xmlns=\"jabber:iq:roster\">\n <item jid=\"" + jid + "\" subscription=\"remove\"/>\n </query>\n</iq>");
+ return this.xmpp.send(node);
};
Session.prototype.sendSubscribe = function(jid) {
return this.xmpp.send(this.presence(jid, 'subscribe'));
};
Session.prototype.sendSubscribed = function(jid) {
@@ -201,11 +201,11 @@
};
Session.prototype.sendUnsubscribed = function(jid) {
return this.xmpp.send(this.presence(jid, 'unsubscribed'));
};
Session.prototype.presence = function(to, type) {
- return $("<presence\n id=\"" + (this.uniqueId()) + "\"\n to=\"" + to + "\"\n type=\"" + type + "\"/>").get(0);
+ return this.xml("<presence\n id=\"" + (this.uniqueId()) + "\"\n to=\"" + to + "\"\n type=\"" + type + "\"/>");
};
Session.prototype.handleIq = function(node) {
var contact, contacts, ns, old, type, _i, _len;
node = $(node);
type = node.attr('type');
@@ -227,21 +227,25 @@
this.notify('roster');
}
return true;
};
Session.prototype.handleMessage = function(node) {
- var body, from, to, type;
+ var body, from, html, thread, to, type;
node = $(node);
to = node.attr('to');
from = node.attr('from');
type = node.attr('type');
+ thread = node.find('thread').first();
body = node.find('body').first();
+ html = node.find('span').first();
if (type === 'chat' && body.size() > 0) {
this.notify('message', {
to: to,
from: from,
type: type,
+ thread: thread.text(),
text: body.text(),
+ html: html.text(),
received: new Date()
});
}
return true;
};
\ No newline at end of file