mirror of
https://github.com/moparisthebest/kaiwa
synced 2024-11-14 21:45:08 -05:00
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
var StrictModel = require('strictmodel');
|
|
var Contacts = require('./contacts');
|
|
|
|
|
|
module.exports = StrictModel.Model.extend({
|
|
session: {
|
|
jid: ['string', 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
|
|
},
|
|
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;
|
|
}
|
|
});
|