2013-09-13 02:43:52 -04:00
|
|
|
/*global app, client*/
|
2013-08-29 23:38:28 -04:00
|
|
|
"use strict";
|
|
|
|
|
2013-09-03 22:18:31 -04:00
|
|
|
var HumanModel = require('human-model');
|
2013-08-20 13:45:06 -04:00
|
|
|
|
|
|
|
|
2013-09-05 19:53:23 -04:00
|
|
|
module.exports = HumanModel.define({
|
2013-08-29 23:38:28 -04:00
|
|
|
initialize: function () {},
|
2013-08-20 13:45:06 -04:00
|
|
|
type: 'resource',
|
|
|
|
session: {
|
2013-09-12 16:24:52 -04:00
|
|
|
id: ['string', true],
|
2013-08-20 13:45:06 -04:00
|
|
|
status: ['string', true, ''],
|
|
|
|
show: ['string', true, ''],
|
|
|
|
priority: ['number', true, 0],
|
2013-09-19 12:27:52 -04:00
|
|
|
chatState: ['string', true, 'gone'],
|
2013-09-09 19:00:13 -04:00
|
|
|
idleSince: 'date',
|
2013-09-13 02:43:52 -04:00
|
|
|
discoInfo: 'object',
|
|
|
|
timezoneOffset: 'number'
|
|
|
|
},
|
2013-10-14 17:04:04 -04:00
|
|
|
derived: {
|
2013-12-31 18:02:07 -05:00
|
|
|
mucDisplayName: {
|
|
|
|
deps: ['id'],
|
|
|
|
fn: function () {
|
|
|
|
return this.id.split('/')[1] || '';
|
|
|
|
}
|
|
|
|
},
|
|
|
|
idle: {
|
|
|
|
deps: ['idleSince'],
|
|
|
|
fn: function () {
|
|
|
|
return !!this.idleSince;
|
|
|
|
}
|
|
|
|
},
|
2013-10-14 17:04:04 -04:00
|
|
|
supportsChatStates: {
|
|
|
|
deps: ['discoInfo'],
|
|
|
|
fn: function () {
|
|
|
|
if (!this.discoInfo) return false;
|
2013-12-16 13:06:03 -05:00
|
|
|
var features = this.discoInfo.features || [];
|
2013-10-14 17:04:04 -04:00
|
|
|
return features.indexOf('http://jabber.org/protocol/chatstate') >= 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
supportsJingleMedia: {
|
|
|
|
deps: ['discoInfo'],
|
|
|
|
fn: function () {
|
|
|
|
if (!this.discoInfo) return false;
|
2013-12-16 17:28:13 -05:00
|
|
|
var features = this.discoInfo.features || [];
|
2013-10-14 17:04:04 -04:00
|
|
|
if (features.indexOf('urn:xmpp:jingle:1') === -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (features.indexOf('urn:xmpp:jingle:apps:rtp:1') === -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (features.indexOf('urn:xmpp:jingle:apps:rtp:audio') === -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (features.indexOf('urn:xmpp:jingle:apps:rtp:video') === -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2013-09-13 02:43:52 -04:00
|
|
|
fetchTimezone: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if (self.timezoneOffset) return;
|
|
|
|
|
|
|
|
app.whenConnected(function () {
|
|
|
|
client.getTime(self.id, function (err, res) {
|
|
|
|
if (err) return;
|
|
|
|
self.timezoneOffset = res.time.tzo;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
fetchDisco: function () {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
if (self.discoInfo) return;
|
|
|
|
|
|
|
|
app.whenConnected(function () {
|
|
|
|
client.getDiscoInfo(self.id, '', function (err, res) {
|
|
|
|
if (err) return;
|
|
|
|
self.discoInfo = res.discoInfo.toJSON();
|
|
|
|
});
|
|
|
|
});
|
2013-08-20 13:45:06 -04:00
|
|
|
}
|
|
|
|
});
|