//>>built // wrapped by build app define("dojox/xmpp/RosterService", ["dijit","dojo","dojox"], function(dijit,dojo,dojox){ dojo.provide("dojox.xmpp.RosterService"); dojox.xmpp.roster = { ADDED: 101, CHANGED: 102, REMOVED: 103 } dojo.declare("dojox.xmpp.RosterService", null, { constructor: function(xmppSession){ this.session = xmppSession; }, addRosterItem: function(jid, name, groups){ if(!jid){ throw new Error ("Roster::addRosterItem() - User ID is null"); } var iqId = this.session.getNextIqId(); var req = { id: iqId, from: this.session.jid + "/" + this.session.resource, type: "set" } var request = new dojox.string.Builder(dojox.xmpp.util.createElement("iq", req, false)); request.append(dojox.xmpp.util.createElement("query",{xmlns: 'jabber:iq:roster'},false)); jid = dojox.xmpp.util.encodeJid(jid); if (jid.indexOf('@')== -1){ jid = jid + '@' + this.session.domain; } request.append(dojox.xmpp.util.createElement("item",{jid:jid,name:dojox.xmpp.util.xmlEncode(name)},false)); if (groups){ for (var i=0; i"); request.append(groups[i]); request.append(""); } } request.append(""); //console.log(request.toString()); var def = this.session.dispatchPacket(request.toString(),"iq",req.id); def.addCallback(this, "verifyRoster"); return def; }, updateRosterItem: function(jid, name, groups){ if (jid.indexOf('@') == -1){ jid += jid + '@' + this.session.domain; } var req = { id: this.session.getNextIqId(), from: this.session.jid + "/" + this.session.resource, type: "set" } var request = new dojox.string.Builder(dojox.xmpp.util.createElement("iq", req, false)); request.append(dojox.xmpp.util.createElement("query",{xmlns: 'jabber:iq:roster'},false)); var i = this.session.getRosterIndex(jid); //item not found if (i==-1){return;} var item = { jid:jid }; if(name){ item.name = name; } else if(this.session.roster[i].name){ item.name = this.session.roster[i].name; } if(item.name) { item.name = dojox.xmpp.util.xmlEncode(item.name); } request.append(dojox.xmpp.util.createElement("item",item,false)); var newGroups = groups ? groups : this.session.roster[i].groups; if (newGroups){ for (var x=0;x"); request.append(newGroups[x]); request.append(""); } } request.append(""); var def = this.session.dispatchPacket(request.toString(),"iq",req.id); def.addCallback(this, "verifyRoster"); return def; }, verifyRoster: function(res){ if (res.getAttribute('type')=='result'){ //this.onAddRosterItem(res.getAttribute('id')); }else{ var err=this.session.processXmppError(res); this.onAddRosterItemFailed(err); } return res; }, addRosterItemToGroup: function(jid, group){ if (!jid) throw new Error("Roster::addRosterItemToGroup() JID is null or undefined"); if (!group) throw new Error("Roster::addRosterItemToGroup() group is null or undefined"); var index = this.session.getRosterIndex(jid); if (index==-1){return;} var item = this.session.roster[index]; var tgroups = []; var found = false; for (var i=0; ((item 0) { //var found = false; for(var j = 0;j < item.groups.length; j++) { if (item.groups[j]==group){ item.groups.splice(j,1); this.updateRosterItem(item.jid, item.name, item.groups); //found=true; } } } } }, renameRosterGroup: function(group, newGroup) { var roster = this.session.roster; for(var i=0;i 0) { //var found = false; for(var j = 0;j < item.groups.length; j++) { if (item.groups[j]==group){ item.groups[j] = newGroup; this.updateRosterItem(item.jid, item.name, item.groups); // found=true; } } } } }, removeRosterItemFromGroup: function(jid, group){ if (!jid) throw new Error("Roster::addRosterItemToGroup() JID is null or undefined"); if (!group) throw new Error("Roster::addRosterItemToGroup() group is null or undefined"); var index = this.session.getRosterIndex(jid); if (index==-1){return;} var item = this.session.roster[index]; var found = false; for (var i=0; ((i"); var def = this.session.dispatchPacket(request.toString(),"iq",req.id); def.addCallback(this, "verifyRoster"); return def; }, //Avatar functions...I removed this stuff for now..can we even do anything useful //with this data even if we have it? getAvatar: function(jid){ }, publishAvatar: function(type,binval){ }, //EVENTS onVerifyRoster: function(id){ //console.log("Roster::onVerifyRoster() - ", id); }, onVerifyRosterFailed: function(err){ //console.log("onVerifyRosterFailed: ", err); } }); });