Update to use stanza.io JID objects

This commit is contained in:
Lance Stout 2013-09-10 00:57:01 -07:00
parent eac51df914
commit dd3f1a27da
4 changed files with 233 additions and 158 deletions

View File

@ -94,7 +94,7 @@ module.exports = function (client, app) {
client.getRoster(function (err, resp) {
resp = resp.toJSON();
app.storage.rosterver.set(me.barejid, resp.roster.ver);
app.storage.rosterver.set(me.jid.bare, resp.roster.ver);
_.each(resp.roster.items, function (item) {
me.setContact(item, true);
@ -114,7 +114,7 @@ module.exports = function (client, app) {
iq = iq.toJSON();
var items = iq.roster.items;
app.storage.rosterver.set(me.barejid, iq.roster.ver);
app.storage.rosterver.set(me.jid.bare, iq.roster.ver);
_.each(items, function (item) {
var contact = me.getContact(item.jid);
@ -126,7 +126,7 @@ module.exports = function (client, app) {
return;
}
me.setContact(item, false);
me.setContact(item, true);
});
});
@ -141,10 +141,11 @@ module.exports = function (client, app) {
var resource = contact.resources.get(pres.from);
if (resource) {
pres.from = pres.from.full;
resource.set(pres);
} else {
resource = new Resource(pres);
resource.cid = pres.from;
resource.cid = pres.from.full;
contact.resources.add(resource);
}
}
@ -154,7 +155,7 @@ module.exports = function (client, app) {
pres = pres.toJSON();
var contact = me.getContact(pres.from);
if (contact) {
var resource = contact.resources.get(pres.from);
var resource = contact.resources.get(pres.from.full);
if (resource) {
contact.resources.remove(resource);
}

File diff suppressed because it is too large Load Diff

View File

@ -8,22 +8,10 @@ var Contact = require('./contact');
module.exports = HumanModel.define({
session: {
jid: ['string', true, ''],
jid: ['object', true],
status: ['string', true, ''],
avatar: ['string', true, '']
},
derived: {
barejid: {
deps: ['jid'],
fn: function () {
var hasResource = this.jid.indexOf('/') > 0;
if (hasResource) {
return this.jid.slice(0, this.jid.indexOf('/'));
}
return this.jid;
}
}
},
collections: {
contacts: Contacts
},
@ -31,15 +19,12 @@ module.exports = HumanModel.define({
if (this.isMe(jid)) {
jid = alt || jid;
}
var hasResource = jid.indexOf('/') > 0;
if (hasResource) {
jid = jid.slice(0, jid.indexOf('/'));
}
return this.contacts.get(jid);
return this.contacts.get(jid.bare);
},
setContact: function (data, create) {
var contact = this.getContact(data.jid);
data.jid = data.jid.bare;
if (contact) {
contact.set(data);
contact.save();
@ -50,14 +35,10 @@ module.exports = HumanModel.define({
}
},
removeContact: function (jid) {
this.contacts.remove(jid);
app.storage.roster.remove(jid);
this.contacts.remove(jid.bare);
app.storage.roster.remove(jid.bare);
},
isMe: function (jid) {
var hasResource = jid.indexOf('/') > 0;
if (hasResource) {
jid = jid.slice(0, jid.indexOf('/'));
}
return jid === this.barejid;
return jid.bare === this.jid.bare;
}
});

View File

@ -52,7 +52,7 @@ module.exports = BasePage.extend({
this.$chatBuffer.removeClass('editing');
e.preventDefault();
return false;
} else {
} else if (!e.ctrlKey) {
if (!this.typing) {
this.typing = true;
client.sendMessage({