var Contact; Contact = (function() { function Contact(node) { node = $(node); this.jid = node.attr('jid'); this.name = node.attr('name'); this.ask = node.attr('ask'); this.subscription = node.attr('subscription'); this.groups = $('group', node).map(function() { return $(this).text(); }).get(); this.presence = []; } Contact.prototype.online = function() { return this.presence.length > 0; }; Contact.prototype.offline = function() { return this.presence.length === 0; }; Contact.prototype.available = function() { var p; return this.online() && ((function() { var _i, _len, _ref, _results; _ref = this.presence; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { p = _ref[_i]; if (!p.away) { _results.push(p); } } return _results; }).call(this)).length > 0; }; Contact.prototype.away = function() { return !this.available(); }; Contact.prototype.status = function() { var available, away, p; available = ((function() { var _i, _len, _ref, _results; _ref = this.presence; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { p = _ref[_i]; if (p.status && !p.away) { _results.push(p.status); } } return _results; }).call(this))[0] || 'Available'; away = ((function() { var _i, _len, _ref, _results; _ref = this.presence; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { p = _ref[_i]; if (p.status && p.away) { _results.push(p.status); } } return _results; }).call(this))[0] || 'Away'; if (this.offline()) { return 'Offline'; } else if (this.away()) { return away; } else { return available; } }; Contact.prototype.update = function(presence) { var p; this.presence = (function() { var _i, _len, _ref, _results; _ref = this.presence; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { p = _ref[_i]; if (p.from !== presence.from) { _results.push(p); } } return _results; }).call(this); if (!presence.type) { this.presence.push(presence); } if (presence.type === 'unsubscribed') { return this.presence = []; } }; return Contact; })();