Update to use stanza.io JID objects
This commit is contained in:
parent
eac51df914
commit
dd3f1a27da
|
@ -94,7 +94,7 @@ module.exports = function (client, app) {
|
||||||
client.getRoster(function (err, resp) {
|
client.getRoster(function (err, resp) {
|
||||||
resp = resp.toJSON();
|
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) {
|
_.each(resp.roster.items, function (item) {
|
||||||
me.setContact(item, true);
|
me.setContact(item, true);
|
||||||
|
@ -114,7 +114,7 @@ module.exports = function (client, app) {
|
||||||
iq = iq.toJSON();
|
iq = iq.toJSON();
|
||||||
var items = iq.roster.items;
|
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) {
|
_.each(items, function (item) {
|
||||||
var contact = me.getContact(item.jid);
|
var contact = me.getContact(item.jid);
|
||||||
|
@ -126,7 +126,7 @@ module.exports = function (client, app) {
|
||||||
return;
|
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);
|
var resource = contact.resources.get(pres.from);
|
||||||
if (resource) {
|
if (resource) {
|
||||||
|
pres.from = pres.from.full;
|
||||||
resource.set(pres);
|
resource.set(pres);
|
||||||
} else {
|
} else {
|
||||||
resource = new Resource(pres);
|
resource = new Resource(pres);
|
||||||
resource.cid = pres.from;
|
resource.cid = pres.from.full;
|
||||||
contact.resources.add(resource);
|
contact.resources.add(resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,7 +155,7 @@ module.exports = function (client, app) {
|
||||||
pres = pres.toJSON();
|
pres = pres.toJSON();
|
||||||
var contact = me.getContact(pres.from);
|
var contact = me.getContact(pres.from);
|
||||||
if (contact) {
|
if (contact) {
|
||||||
var resource = contact.resources.get(pres.from);
|
var resource = contact.resources.get(pres.from.full);
|
||||||
if (resource) {
|
if (resource) {
|
||||||
contact.resources.remove(resource);
|
contact.resources.remove(resource);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,22 +8,10 @@ var Contact = require('./contact');
|
||||||
|
|
||||||
module.exports = HumanModel.define({
|
module.exports = HumanModel.define({
|
||||||
session: {
|
session: {
|
||||||
jid: ['string', true, ''],
|
jid: ['object', true],
|
||||||
status: ['string', true, ''],
|
status: ['string', true, ''],
|
||||||
avatar: ['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: {
|
collections: {
|
||||||
contacts: Contacts
|
contacts: Contacts
|
||||||
},
|
},
|
||||||
|
@ -31,15 +19,12 @@ module.exports = HumanModel.define({
|
||||||
if (this.isMe(jid)) {
|
if (this.isMe(jid)) {
|
||||||
jid = alt || jid;
|
jid = alt || jid;
|
||||||
}
|
}
|
||||||
|
return this.contacts.get(jid.bare);
|
||||||
var hasResource = jid.indexOf('/') > 0;
|
|
||||||
if (hasResource) {
|
|
||||||
jid = jid.slice(0, jid.indexOf('/'));
|
|
||||||
}
|
|
||||||
return this.contacts.get(jid);
|
|
||||||
},
|
},
|
||||||
setContact: function (data, create) {
|
setContact: function (data, create) {
|
||||||
var contact = this.getContact(data.jid);
|
var contact = this.getContact(data.jid);
|
||||||
|
data.jid = data.jid.bare;
|
||||||
|
|
||||||
if (contact) {
|
if (contact) {
|
||||||
contact.set(data);
|
contact.set(data);
|
||||||
contact.save();
|
contact.save();
|
||||||
|
@ -50,14 +35,10 @@ module.exports = HumanModel.define({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeContact: function (jid) {
|
removeContact: function (jid) {
|
||||||
this.contacts.remove(jid);
|
this.contacts.remove(jid.bare);
|
||||||
app.storage.roster.remove(jid);
|
app.storage.roster.remove(jid.bare);
|
||||||
},
|
},
|
||||||
isMe: function (jid) {
|
isMe: function (jid) {
|
||||||
var hasResource = jid.indexOf('/') > 0;
|
return jid.bare === this.jid.bare;
|
||||||
if (hasResource) {
|
|
||||||
jid = jid.slice(0, jid.indexOf('/'));
|
|
||||||
}
|
|
||||||
return jid === this.barejid;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -52,7 +52,7 @@ module.exports = BasePage.extend({
|
||||||
this.$chatBuffer.removeClass('editing');
|
this.$chatBuffer.removeClass('editing');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else if (!e.ctrlKey) {
|
||||||
if (!this.typing) {
|
if (!this.typing) {
|
||||||
this.typing = true;
|
this.typing = true;
|
||||||
client.sendMessage({
|
client.sendMessage({
|
||||||
|
|
Loading…
Reference in New Issue