# HG changeset patch # User Sonny Piers # Date 1330013242 -3600 # Node ID 595be4a8584f5d5eb19860e54bb3317be5cd1d16 # Parent 0f6f213f0a33612d6645dd0fe5f8bfc087b04dc0 fix the roster plugin diff --git a/plugins/roster.js b/plugins/roster.js --- a/plugins/roster.js +++ b/plugins/roster.js @@ -24,14 +24,14 @@ Lightstring.plugins['roster'] = { roster: 'jabber:iq:roster' }, stanzas: { - get: function() { + 'get': function() { return "" + - "" + + "" + ""; }, add: function(aAddress, aGroups) { var iq = "" + - "" + + "" + "" + "" + ""; @@ -44,45 +44,51 @@ Lightstring.plugins['roster'] = { }, remove: function(aAddress) { return "" + - "" + + "" + "" + "" + ""; } }, methods: { - get: function(aResult, aError) { - this.send(this.stanza.roster.get(), function(stanza) { + 'get': function(aSuccess, aError) { + this.send(Lightstring.stanzas.roster.get(), function(stanza) { var contacts = []; - var children = stanza.DOM.firstChild.childNodes; - var length = children.length; + var items = stanza.DOM.getElementsByTagName('item'); + + for (var i = 0; i < items.length; i++) { + var item = items[i]; + var contact = {} - for (var i = 0; i < length; i++) { - var item = children[i]; - var jid = item.getAttributeNS(null, 'jid'); - var name = item.getAttributeNS(null, 'name'); - var subscription = item.getAttributeNS(null, 'subscription'); - var groups = item.children; - var contact = {}; + var jid = item.getAttribute('jid'); + if (jid) + contact.jid = jid; + + var name = item.getAttribute('name'); if (name) contact.name = name; - if (jid) - contact.jid = jid; + + var subscription = item.getAttribute('subscription'); if (subscription) contact.subscription = subscription; - if (groups.length > 0) { + + var groups = item.getElementsByTagName('group'); + if(groups) { contact.groups = []; - groups.forEach(function(group) { - contact.groups.push(group.textContent); - }); + for (var y = 0; y < groups.length; y++) + contact.groups.push(groups[y].textContent); } contacts.push(contact); } - if (aResult) - aResult(contacts); + stanza.roster = { + contacts: contacts + }; + + if (aSuccess) + aSuccess(stanza); }, aError); } }