# HG changeset patch # User Emmanuel Gil Peyrot # Date 1328064672 -3600 # Node ID 48e2bd6b188560ba3995e56ea643a1c6fbc8dd50 # Parent 63c1c8bc8c19bd364e2064792df39162e57a4978 Fix roster plugin. diff --git a/plugins/roster.js b/plugins/roster.js --- a/plugins/roster.js +++ b/plugins/roster.js @@ -19,50 +19,71 @@ ////////// //Roster// ////////// -Lightstring.NS.roster = 'jabber:iq:roster'; -Lightstring.stanza.roster = { - 'get': function() { - return ""; +Lightstring.plugins['roster'] = { + namespaces: { + roster: 'jabber:iq:roster' + }, + stanzas: { + get: function() { + return "" + + "" + + ""; + }, + add: function(aAddress, aGroups) { + var iq = "" + + "" + + "" + + "" + + ""; + for (var i = 0; i < aGroups.length; i++) { + if (i === 0) + iq.querySelector('item').appendChild(document.createElement('group')); + iq.querySelector('group').appendChild(document.createElement(aGroups[i])); + } + return iq; + }, + remove: function(aAddress) { + return "" + + "" + + "" + + "" + + ""; + } }, - add: function(aAddress, aGroups, aCustomName) { - var iq = $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress}).tree(); - if(aCustomName) iq.querySelector('item').setAttribute(aCustomName); - for (var i=0; i 0) { + contact.groups = []; + groups.forEach(function(group) { + contact.groups.push(group.textContent); + }); + } + + contacts.push(contact); + } + + if (aResult) + aResult(contacts); + }, aError); } - return iq; - }, - remove: function(aAddress) { - return $iq({type: 'set'}).c('query', {xmlns: Lightstring.NS.roster}).c('item', {jid: aAddress, subscription: 'remove'}).tree(); } }; -Lightstring.getRoster = function(connection, aCallback) { - connection.send(this.stanza.roster.get(), function(stanza){ - var contacts = []; - var elems = stanza.DOM.querySelectorAll('item'); - for(var i = 0; i 0) { - contact.groups = []; - groups.forEach(function(group) { - contact.groups.push(group.textContent); - }); - } - - contacts.push(contact); - }; - aCallback(contacts); - }); -}