2013-06-03 18:51:30 -04:00
|
|
|
var StrictModel = require('strictmodel');
|
2013-08-20 13:45:06 -04:00
|
|
|
var Contacts = require('./contacts');
|
2013-06-03 18:51:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = StrictModel.Model.extend({
|
|
|
|
session: {
|
2013-08-20 13:45:06 -04:00
|
|
|
jid: ['string', true, ''],
|
|
|
|
status: ['string', true, ''],
|
|
|
|
avatar: ['string', true, '']
|
2013-06-03 18:51:30 -04:00
|
|
|
},
|
|
|
|
derived: {
|
2013-08-20 13:45:06 -04:00
|
|
|
barejid: {
|
|
|
|
deps: ['jid'],
|
2013-06-03 18:51:30 -04:00
|
|
|
fn: function () {
|
2013-08-20 13:45:06 -04:00
|
|
|
var hasResource = this.jid.indexOf('/') > 0;
|
|
|
|
if (hasResource) {
|
|
|
|
return this.jid.slice(0, this.jid.indexOf('/'));
|
|
|
|
}
|
|
|
|
return this.jid;
|
2013-06-03 18:51:30 -04:00
|
|
|
}
|
|
|
|
}
|
2013-08-20 13:45:06 -04:00
|
|
|
},
|
|
|
|
collections: {
|
|
|
|
contacts: Contacts
|
|
|
|
},
|
|
|
|
getContact: function (jid, alt) {
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
isMe: function (jid) {
|
|
|
|
var hasResource = jid.indexOf('/') > 0;
|
|
|
|
if (hasResource) {
|
|
|
|
jid = jid.slice(0, jid.indexOf('/'));
|
|
|
|
}
|
|
|
|
return jid === this.barejid;
|
2013-06-03 18:51:30 -04:00
|
|
|
}
|
|
|
|
});
|