dojox/xmpp/RosterService.js

  • Provides:

    • dojox.xmpp.RosterService
  • dojox.xmpp.RosterService

    • type
      Function
    • parameters:
      • xmppSession: (typeof )
    • source: [view]
        this.session = xmppSession;
    • summary
  • dojox.xmpp.RosterService.addRosterItem

    • type
      Function
    • parameters:
      • jid: (typeof )
      • name: (typeof )
      • groups: (typeof )
    • source: [view]
        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("");
          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;
    • summary
  • dojox.xmpp.RosterService.updateRosterItem

    • type
      Function
    • parameters:
      • jid: (typeof )
      • name: (typeof )
      • groups: (typeof )
    • source: [view]
        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("");
          request.append(newGroups[x]);
          request.append("
      ");
         }
        }

        
        request.append("");

        
        var def = this.session.dispatchPacket(request.toString(),"iq",req.id);
        def.addCallback(this, "verifyRoster");
        return def;
    • summary
  • dojox.xmpp.RosterService.verifyRoster

    • type
      Function
    • parameters:
      • res: (typeof )
    • source: [view]
        if (res.getAttribute('type')=='result'){
         //this.onAddRosterItem(res.getAttribute('id'));
        }else{
         var err=this.session.processXmppError(res);
         this.onAddRosterItemFailed(err);
        }
        return res;
    • summary
  • dojox.xmpp.RosterService.addRosterItemToGroup

    • type
      Function
    • parameters:
      • jid: (typeof )
      • group: (typeof )
    • source: [view]
        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   if (item.groups[i]!=group){continue;}
         found=true;
        }

       
        if(!found){
         return this.updateRosterItem(jid, item.name, item.groups.concat(group),index);
        }

       
        return dojox.xmpp.xmpp.INVALID_ID;
    • summary
  • dojox.xmpp.RosterService.removeRosterGroup

    • type
      Function
    • parameters:
      • group: (typeof )
    • source: [view]
        var roster = this.session.roster;
        for(var i=0;i   var item = roster[i];
         if(item.groups.length > 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;
           }
          }
         }
        }
    • summary
  • dojox.xmpp.RosterService.renameRosterGroup

    • type
      Function
    • parameters:
      • group: (typeof )
      • newGroup: (typeof )
    • source: [view]
        var roster = this.session.roster;
        for(var i=0;i   var item = roster[i];
         if(item.groups.length > 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;
           }
          }
         }
        }
    • summary
  • dojox.xmpp.RosterService.removeRosterItemFromGroup

    • type
      Function
    • parameters:
      • jid: (typeof )
      • group: (typeof )
    • source: [view]
        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   if (item.groups[i]!=group){continue;}
         found=true;
         index = i;
        }


        if(found==true){
         item.groups.splice(index,1);
         return this.updateRosterItem(jid, item.name, item.groups);
        }

        
        return dojox.xmpp.xmpp.INVALID_ID;
    • summary
  • dojox.xmpp.RosterService.rosterItemRenameGroup

    • type
      Function
    • parameters:
      • jid: (typeof )
      • oldGroup: (typeof )
      • newGroup: (typeof )
    • source: [view]
        if (!jid) throw new Error("Roster::rosterItemRenameGroup() JID is null or undefined");
        if (!newGroup) throw new Error("Roster::rosterItemRenameGroup() 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   if (item.groups[i]==oldGroup){
          item.groups[i] = newGroup;
          found=true;
         }
        }


        if(found==true){
         return this.updateRosterItem(jid, item.name, item.groups);
        }

        
        return dojox.xmpp.xmpp.INVALID_ID;
    • summary
  • dojox.xmpp.RosterService.renameRosterItem

    • type
      Function
    • parameters:
      • jid: (typeof )
      • newName: (typeof )
    • source: [view]
        if (!jid) throw new Error("Roster::addRosterItemToGroup() JID is null or undefined");
        if (!newName) throw new Error("Roster::addRosterItemToGroup() New Name is null or undefined");


        var index = this.session.getRosterIndex(jid);
        if (index==-1){return;}


        return this.updateRosterItem(jid, newName, this.session.roster.groups,index);
    • summary
  • dojox.xmpp.RosterService.removeRosterItem

    • type
      Function
    • parameters:
      • jid: (typeof )
    • source: [view]
        if (!jid) throw new Error("Roster::addRosterItemToGroup() JID is null or undefined");

        
        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));


        if (jid.indexOf('@')== -1){
         jid += jid + '@' + this.session.domain;
        }


        request.append(dojox.xmpp.util.createElement('item',{jid:jid,subscription:"remove"},true));


        request.append("");


        var def = this.session.dispatchPacket(request.toString(),"iq",req.id);
        def.addCallback(this, "verifyRoster");
        return def;
    • summary
  • dojox.xmpp.RosterService.getAvatar

    • type
      Function
    • parameters:
      • jid: (typeof )
    • source: [view]
    • summary
  • dojox.xmpp.RosterService.publishAvatar

    • type
      Function
    • parameters:
      • type: (typeof )
      • binval: (typeof )
    • source: [view]
    • summary
  • dojox.xmpp.RosterService.onVerifyRoster

    • type
      Function
    • parameters:
      • id: (typeof )
    • source: [view]
      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("");
          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("");
          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   if (item.groups[i]!=group){continue;}
         found=true;
        }

       
        if(!found){
         return this.updateRosterItem(jid, item.name, item.groups.concat(group),index);
        }

       
        return dojox.xmpp.xmpp.INVALID_ID;
       },

       
       removeRosterGroup: function(group) {
        var roster = this.session.roster;
        for(var i=0;i   var item = roster[i];
         if(item.groups.length > 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   var item = roster[i];
         if(item.groups.length > 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   if (item.groups[i]!=group){continue;}
         found=true;
         index = i;
        }


        if(found==true){
         item.groups.splice(index,1);
         return this.updateRosterItem(jid, item.name, item.groups);
        }

        
        return dojox.xmpp.xmpp.INVALID_ID;
       },

       
       rosterItemRenameGroup: function(jid, oldGroup, newGroup){
        if (!jid) throw new Error("Roster::rosterItemRenameGroup() JID is null or undefined");
        if (!newGroup) throw new Error("Roster::rosterItemRenameGroup() 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   if (item.groups[i]==oldGroup){
          item.groups[i] = newGroup;
          found=true;
         }
        }


        if(found==true){
         return this.updateRosterItem(jid, item.name, item.groups);
        }

        
        return dojox.xmpp.xmpp.INVALID_ID;
       },


       renameRosterItem: function(jid,newName){
        if (!jid) throw new Error("Roster::addRosterItemToGroup() JID is null or undefined");
        if (!newName) throw new Error("Roster::addRosterItemToGroup() New Name is null or undefined");


        var index = this.session.getRosterIndex(jid);
        if (index==-1){return;}


        return this.updateRosterItem(jid, newName, this.session.roster.groups,index);
       },


       removeRosterItem: function(jid){
        if (!jid) throw new Error("Roster::addRosterItemToGroup() JID is null or undefined");

        
        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));


        if (jid.indexOf('@')== -1){
         jid += jid + '@' + this.session.domain;
        }


        request.append(dojox.xmpp.util.createElement('item',{jid:jid,subscription:"remove"},true));


        request.append("");


        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);
    • summary
  • dojox.xmpp.RosterService.onVerifyRosterFailed

    • type
      Function
    • parameters:
      • err: (typeof )
    • source: [view]
      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("");
          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("");
          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   if (item.groups[i]!=group){continue;}
         found=true;
        }

       
        if(!found){
         return this.updateRosterItem(jid, item.name, item.groups.concat(group),index);
        }

       
        return dojox.xmpp.xmpp.INVALID_ID;
       },

       
       removeRosterGroup: function(group) {
        var roster = this.session.roster;
        for(var i=0;i   var item = roster[i];
         if(item.groups.length > 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   var item = roster[i];
         if(item.groups.length > 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   if (item.groups[i]!=group){continue;}
         found=true;
         index = i;
        }


        if(found==true){
         item.groups.splice(index,1);
         return this.updateRosterItem(jid, item.name, item.groups);
        }

        
        return dojox.xmpp.xmpp.INVALID_ID;
       },

       
       rosterItemRenameGroup: function(jid, oldGroup, newGroup){
        if (!jid) throw new Error("Roster::rosterItemRenameGroup() JID is null or undefined");
        if (!newGroup) throw new Error("Roster::rosterItemRenameGroup() 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   if (item.groups[i]==oldGroup){
          item.groups[i] = newGroup;
          found=true;
         }
        }


        if(found==true){
         return this.updateRosterItem(jid, item.name, item.groups);
        }

        
        return dojox.xmpp.xmpp.INVALID_ID;
       },


       renameRosterItem: function(jid,newName){
        if (!jid) throw new Error("Roster::addRosterItemToGroup() JID is null or undefined");
        if (!newName) throw new Error("Roster::addRosterItemToGroup() New Name is null or undefined");


        var index = this.session.getRosterIndex(jid);
        if (index==-1){return;}


        return this.updateRosterItem(jid, newName, this.session.roster.groups,index);
       },


       removeRosterItem: function(jid){
        if (!jid) throw new Error("Roster::addRosterItemToGroup() JID is null or undefined");

        
        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));


        if (jid.indexOf('@')== -1){
         jid += jid + '@' + this.session.domain;
        }


        request.append(dojox.xmpp.util.createElement('item',{jid:jid,subscription:"remove"},true));


        request.append("");


        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);
    • summary
  • dojox.xmpp.RosterService.session

    • summary
  • dojox.xmpp.roster

    • type
      Object
    • summary
  • dojox.xmpp.roster.ADDED

    • summary
  • dojox.xmpp.roster.CHANGED

    • summary
  • dojox.xmpp.roster.REMOVED

    • summary
  • dojox.xmpp

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary