dojox/xmpp/PresenceService.js

  • Provides:

    • dojox.xmpp.PresenceService
  • dojox.xmpp.PresenceService

    • type
      Function
    • parameters:
      • xmppService: (typeof )
    • source: [view]
        this.session= xmppService;
        this.isInvisible = false;
        this.avatarHash = null;
        this.presence = null;
        this.restrictedContactjids = {};
    • summary
  • dojox.xmpp.PresenceService.publish

    • type
      Function
    • parameters:
      • presence: (typeof )
    • source: [view]
      dojo.provide("dojox.xmpp.PresenceService");


      dojox.xmpp.presence = {
       UPDATE: 201,
       SUBSCRIPTION_REQUEST: 202,
      // SUBSCRIPTION_REQUEST_PENDING: 203,
       /* used when 'ask' attribute is absent on a roster item */
       SUBSCRIPTION_SUBSTATUS_NONE: 204,


       SUBSCRIPTION_NONE: 'none',
       SUBSCRIPTION_FROM: 'from',
       SUBSCRIPTION_TO: 'to',
       SUBSCRIPTION_BOTH: 'both',
       SUBSCRIPTION_REQUEST_PENDING: 'pending',


       STATUS_ONLINE: 'online',
       STATUS_AWAY: 'away',
       STATUS_CHAT: 'chat',
       STATUS_DND: 'dnd',
       STATUS_EXTENDED_AWAY: 'xa',
       STATUS_OFFLINE: 'offline',

       
       STATUS_INVISIBLE: 'invisible'
      }


      dojo.declare("dojox.xmpp.PresenceService", null, {
       constructor: function(xmppService){
        this.session= xmppService;
        this.isInvisible = false;
        this.avatarHash = null;
        this.presence = null;
        this.restrictedContactjids = {};
       },


       publish: function(presence){
        ////console.log("Presence::publish() ", presence);
        this.presence = presence;
        this._setPresence();
    • summary
  • dojox.xmpp.PresenceService.sendAvatarHash

    • type
      Function
    • parameters:
      • avatarHash: (typeof )
    • source: [view]
         this.avatarHash = avatarHash;
         this._setPresence();
    • summary
  • dojox.xmpp.PresenceService._setPresence

    • type
      Function
    • source: [view]
         var presence =  this.presence;
         var p = {xmlns: 'jabber:client'};


         if (presence && presence.to){
          p.to = presence.to;
         }


         if (presence.show && presence.show==dojox.xmpp.presence.STATUS_OFFLINE){
          p.type = 'unavailable';
         }


         if (presence.show && presence.show==dojox.xmpp.presence.STATUS_INVISIBLE) {
          this._setInvisible();
          this.isInvisible = true;
          return;
         };


         if(this.isInvisible) {
          //console.log("was invisible, making visible");
          this._setVisible();
         }


         var req = new dojox.string.Builder(dojox.xmpp.util.createElement("presence",p, false));


         if (presence.show && presence.show!=dojox.xmpp.presence.STATUS_OFFLINE ) {
          req.append(dojox.xmpp.util.createElement("show",{},false));
          req.append(presence.show);
          req.append("");
         }


         if(presence.status) {
          req.append(dojox.xmpp.util.createElement("status",{},false));
          req.append(presence.status);
          req.append("");
         }


         if(this.avatarHash) {
          req.append(dojox.xmpp.util.createElement("x",{xmlns: 'vcard-temp:x:update'},false));
           req.append(dojox.xmpp.util.createElement("photo",{},false));
           req.append(this.avatarHash);
           req.append("");
          req.append("");
         }




         if (presence.priority && presence.show!=dojox.xmpp.presence.STATUS_OFFLINE){
          if(presence.priority > 127 || presence.priority < -128){
           presence.priority = 5;
          }
          req.append(dojox.xmpp.util.createElement("priority",{},false));
          req.append(presence.priority);
          req.append("");
         }


         req.append("");
         this.session.dispatchPacket(req.toString());
    • summary
  • dojox.xmpp.PresenceService.toggleBlockContact

    • type
      Function
    • parameters:
      • jid: (typeof )
    • source: [view]
        if(!this.restrictedContactjids[jid]) {
         this.restrictedContactjids[jid] = this._createRestrictedJid();
        }

        
        this.restrictedContactjids[jid].blocked = !this.restrictedContactjids[jid].blocked;
        //console.log("setting outbound block for ", jid, this.restrictedContactjids[jid]);
        this._updateRestricted();
        return this.restrictedContactjids;
    • summary
  • dojox.xmpp.PresenceService.toggleContactInvisiblity

    • type
      Function
    • parameters:
      • jid: (typeof )
    • source: [view]
        if(!this.restrictedContactjids[jid]) {
         this.restrictedContactjids[jid] = this._createRestrictedJid();
        }

        
        this.restrictedContactjids[jid].invisible = !this.restrictedContactjids[jid].invisible;
        //console.log("setting outbound presence for ", jid, this.restrictedContactjids[jid]);
        this._updateRestricted();
        return this.restrictedContactjids;
    • summary
  • dojox.xmpp.PresenceService._createRestrictedJid

    • type
      Function
    • source: [view]
        return {invisible: false, blocked:false};
    • summary
  • dojox.xmpp.PresenceService._updateRestricted

    • type
      Function
    • source: [view]
        var props={
         id: this.session.getNextIqId(),
         from: this.session.jid + "/" + this.session.resource,
         type: "set"
        };

        
        var req = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",props,false));
        req.append(dojox.xmpp.util.createElement("query",{xmlns: "jabber:iq:privacy"},false));
        req.append(dojox.xmpp.util.createElement("list",{name: "iwcRestrictedContacts"},false))
        var count = 1;
        for(var jid in this.restrictedContactjids) {
         var item = this.restrictedContactjids[jid];
         //console.log("restricted ", jid, item);
         if(item.blocked || item.invisible) {
          req.append(dojox.xmpp.util.createElement("item",{value: dojox.xmpp.util.encodeJid(jid), action: "deny", order: count++},false));
          if(item.blocked) {
           req.append(dojox.xmpp.util.createElement("message",{},true));
          }
          if(item.invisible) {
           req.append(dojox.xmpp.util.createElement("presence-out",{},true));
          }
          req.append("");
         } else {
          delete this.restrictedContactjids[jid];
         }

         

        

         
        }
          req.append("");
         req.append("");
        req.append("");
        //console.log("Restricted list: ", req.toString());

        
         var req2 = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",props,false));
          req2.append(dojox.xmpp.util.createElement("query",{xmlns: "jabber:iq:privacy"},false));
           req2.append(dojox.xmpp.util.createElement("active",{name:"iwcRestrictedContacts"},true));
          req2.append("");
         req2.append("");

        
          //console.log("Activate list: ", req2.toString());

        

        
        this.session.dispatchPacket(req.toString());
        this.session.dispatchPacket(req2.toString());
    • summary
  • dojox.xmpp.PresenceService._setVisible

    • type
      Function
    • source: [view]
         var props={
          id: this.session.getNextIqId(),
          from: this.session.jid + "/" + this.session.resource,
          type: "set"
         };
         var req = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",props,false));
          req.append(dojox.xmpp.util.createElement("query",{xmlns: "jabber:iq:privacy"},false));
           req.append(dojox.xmpp.util.createElement("active",{},true));
          req.append("");
         req.append("");
         //console.log(req.toString());
         this.session.dispatchPacket(req.toString());
    • summary
  • dojox.xmpp.PresenceService._setInvisible

    • type
      Function
    • source: [view]
      dojo.provide("dojox.xmpp.PresenceService");


      dojox.xmpp.presence = {
       UPDATE: 201,
       SUBSCRIPTION_REQUEST: 202,
      // SUBSCRIPTION_REQUEST_PENDING: 203,
       /* used when 'ask' attribute is absent on a roster item */
       SUBSCRIPTION_SUBSTATUS_NONE: 204,


       SUBSCRIPTION_NONE: 'none',
       SUBSCRIPTION_FROM: 'from',
       SUBSCRIPTION_TO: 'to',
       SUBSCRIPTION_BOTH: 'both',
       SUBSCRIPTION_REQUEST_PENDING: 'pending',


       STATUS_ONLINE: 'online',
       STATUS_AWAY: 'away',
       STATUS_CHAT: 'chat',
       STATUS_DND: 'dnd',
       STATUS_EXTENDED_AWAY: 'xa',
       STATUS_OFFLINE: 'offline',

       
       STATUS_INVISIBLE: 'invisible'
      }


      dojo.declare("dojox.xmpp.PresenceService", null, {
       constructor: function(xmppService){
        this.session= xmppService;
        this.isInvisible = false;
        this.avatarHash = null;
        this.presence = null;
        this.restrictedContactjids = {};
       },


       publish: function(presence){
        ////console.log("Presence::publish() ", presence);
        this.presence = presence;
        this._setPresence();
       },

       
       /**
       
       
        sha1-hash-of-image
       

       


       

       
       
       
       
       

       


       
       */

       
       sendAvatarHash: function(avatarHash) {
         this.avatarHash = avatarHash;
         this._setPresence();
       },

       

       
       _setPresence: function() {
         var presence =  this.presence;
         var p = {xmlns: 'jabber:client'};


         if (presence && presence.to){
          p.to = presence.to;
         }


         if (presence.show && presence.show==dojox.xmpp.presence.STATUS_OFFLINE){
          p.type = 'unavailable';
         }


         if (presence.show && presence.show==dojox.xmpp.presence.STATUS_INVISIBLE) {
          this._setInvisible();
          this.isInvisible = true;
          return;
         };


         if(this.isInvisible) {
          //console.log("was invisible, making visible");
          this._setVisible();
         }


         var req = new dojox.string.Builder(dojox.xmpp.util.createElement("presence",p, false));


         if (presence.show && presence.show!=dojox.xmpp.presence.STATUS_OFFLINE ) {
          req.append(dojox.xmpp.util.createElement("show",{},false));
          req.append(presence.show);
          req.append("");
         }


         if(presence.status) {
          req.append(dojox.xmpp.util.createElement("status",{},false));
          req.append(presence.status);
          req.append("");
         }


         if(this.avatarHash) {
          req.append(dojox.xmpp.util.createElement("x",{xmlns: 'vcard-temp:x:update'},false));
           req.append(dojox.xmpp.util.createElement("photo",{},false));
           req.append(this.avatarHash);
           req.append("");
          req.append("");
         }




         if (presence.priority && presence.show!=dojox.xmpp.presence.STATUS_OFFLINE){
          if(presence.priority > 127 || presence.priority < -128){
           presence.priority = 5;
          }
          req.append(dojox.xmpp.util.createElement("priority",{},false));
          req.append(presence.priority);
          req.append("");
         }


         req.append("");
         this.session.dispatchPacket(req.toString());
       },

       
       /*

       
       
       
       
       
       
       

       

       

       


       
       
       
       
       

       


       
       Make visible:
       
       
       
       

       


       
       */

       
       toggleBlockContact: function(jid) {
        if(!this.restrictedContactjids[jid]) {
         this.restrictedContactjids[jid] = this._createRestrictedJid();
        }

        
        this.restrictedContactjids[jid].blocked = !this.restrictedContactjids[jid].blocked;
        //console.log("setting outbound block for ", jid, this.restrictedContactjids[jid]);
        this._updateRestricted();
        return this.restrictedContactjids;
       },

       

       
       toggleContactInvisiblity: function(jid) {
        if(!this.restrictedContactjids[jid]) {
         this.restrictedContactjids[jid] = this._createRestrictedJid();
        }

        
        this.restrictedContactjids[jid].invisible = !this.restrictedContactjids[jid].invisible;
        //console.log("setting outbound presence for ", jid, this.restrictedContactjids[jid]);
        this._updateRestricted();
        return this.restrictedContactjids;
       },

       
       _createRestrictedJid: function() {
        return {invisible: false, blocked:false};
       },

       
       _updateRestricted: function() {

        
        var props={
         id: this.session.getNextIqId(),
         from: this.session.jid + "/" + this.session.resource,
         type: "set"
        };

        
        var req = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",props,false));
        req.append(dojox.xmpp.util.createElement("query",{xmlns: "jabber:iq:privacy"},false));
        req.append(dojox.xmpp.util.createElement("list",{name: "iwcRestrictedContacts"},false))
        var count = 1;
        for(var jid in this.restrictedContactjids) {
         var item = this.restrictedContactjids[jid];
         //console.log("restricted ", jid, item);
         if(item.blocked || item.invisible) {
          req.append(dojox.xmpp.util.createElement("item",{value: dojox.xmpp.util.encodeJid(jid), action: "deny", order: count++},false));
          if(item.blocked) {
           req.append(dojox.xmpp.util.createElement("message",{},true));
          }
          if(item.invisible) {
           req.append(dojox.xmpp.util.createElement("presence-out",{},true));
          }
          req.append("");
         } else {
          delete this.restrictedContactjids[jid];
         }

         

        

         
        }
          req.append("");
         req.append("");
        req.append("");
        //console.log("Restricted list: ", req.toString());

        
         var req2 = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",props,false));
          req2.append(dojox.xmpp.util.createElement("query",{xmlns: "jabber:iq:privacy"},false));
           req2.append(dojox.xmpp.util.createElement("active",{name:"iwcRestrictedContacts"},true));
          req2.append("");
         req2.append("");

        
          //console.log("Activate list: ", req2.toString());

        

        
        this.session.dispatchPacket(req.toString());
        this.session.dispatchPacket(req2.toString());
       },

       
       _setVisible: function() {
         var props={
          id: this.session.getNextIqId(),
          from: this.session.jid + "/" + this.session.resource,
          type: "set"
         };
         var req = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",props,false));
          req.append(dojox.xmpp.util.createElement("query",{xmlns: "jabber:iq:privacy"},false));
           req.append(dojox.xmpp.util.createElement("active",{},true));
          req.append("");
         req.append("");
         //console.log(req.toString());
         this.session.dispatchPacket(req.toString());
       },

       
       _setInvisible: function() {
        //console.log("Setting user as invisible");
        var props={
         id: this.session.getNextIqId(),
         from: this.session.jid + "/" + this.session.resource,
         type: "set"
        };
        var req = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",props,false));
         req.append(dojox.xmpp.util.createElement("query",{xmlns: "jabber:iq:privacy"},false));
          req.append(dojox.xmpp.util.createElement("list",{name: "invisible"},false))
           req.append(dojox.xmpp.util.createElement("item",{action: "deny", order: "1"},false))
            req.append(dojox.xmpp.util.createElement("presence-out",{},true));
           req.append("");
          req.append("");
         req.append("");
        req.append("");

        

        
        props={
         id: this.session.getNextIqId(),
         from: this.session.jid + "/" + this.session.resource,
         type: "set"
        };


        var req2 = new dojox.string.Builder(dojox.xmpp.util.createElement("iq",props,false));
         req2.append(dojox.xmpp.util.createElement("query",{xmlns: "jabber:iq:privacy"},false));
          req2.append(dojox.xmpp.util.createElement("active",{name:"invisible"},true));
         req2.append("");
        req2.append("");
        //console.log(req.toString());
        //console.log(req2.toString());
        this.session.dispatchPacket(req.toString());
        this.session.dispatchPacket(req2.toString());
    • summary
  • dojox.xmpp.PresenceService._manageSubscriptions

    • type
      Function
    • parameters:
      • contact: (typeof )
      • type: (typeof )
    • source: [view]
        if (!contact){return;}

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


        var req = dojox.xmpp.util.createElement("presence",{to:contact,type:type},true);
        this.session.dispatchPacket(req);
    • summary
  • dojox.xmpp.PresenceService.subscribe

    • type
      Function
    • parameters:
      • contact: (typeof )
    • source: [view]
        this._manageSubscriptions(contact, "subscribe");
    • summary
  • dojox.xmpp.PresenceService.approveSubscription

    • type
      Function
    • parameters:
      • contact: (typeof )
    • source: [view]
        this._manageSubscriptions(contact, "subscribed");
    • summary
  • dojox.xmpp.PresenceService.unsubscribe

    • type
      Function
    • parameters:
      • contact: (typeof )
    • source: [view]
        this._manageSubscriptions(contact, "unsubscribe");
    • summary
  • dojox.xmpp.PresenceService.declineSubscription

    • type
      Function
    • parameters:
      • contact: (typeof )
    • source: [view]
        this._manageSubscriptions(contact, "unsubscribed");
    • summary
  • dojox.xmpp.PresenceService.cancelSubscription

    • type
      Function
    • parameters:
      • contact: (typeof )
    • source: [view]
        this._manageSubscriptions(contact, "unsubscribed");
    • summary
  • dojox.xmpp.PresenceService.presence

    • summary
  • dojox.xmpp.PresenceService.avatarHash

    • summary
  • dojox.xmpp.PresenceService.isInvisible

    • summary
  • dojox.xmpp.PresenceService.session

    • summary
  • dojox.xmpp.PresenceService.restrictedContactjids

    • summary
  • dojox.xmpp.presence

    • type
      Object
    • summary
  • dojox.xmpp.presence.UPDATE

    • summary
  • dojox.xmpp.presence.SUBSCRIPTION_REQUEST

    • summary
  • dojox.xmpp.presence.SUBSCRIPTION_SUBSTATUS_NONE

    • summary
  • dojox.xmpp.presence.SUBSCRIPTION_NONE

    • summary
  • dojox.xmpp.presence.SUBSCRIPTION_FROM

    • summary
  • dojox.xmpp.presence.SUBSCRIPTION_TO

    • summary
  • dojox.xmpp.presence.SUBSCRIPTION_BOTH

    • summary
  • dojox.xmpp.presence.SUBSCRIPTION_REQUEST_PENDING

    • summary
  • dojox.xmpp.presence.STATUS_ONLINE

    • summary
  • dojox.xmpp.presence.STATUS_AWAY

    • summary
  • dojox.xmpp.presence.STATUS_CHAT

    • summary
  • dojox.xmpp.presence.STATUS_DND

    • summary
  • dojox.xmpp.presence.STATUS_EXTENDED_AWAY

    • summary
  • dojox.xmpp.presence.STATUS_OFFLINE

    • summary
  • dojox.xmpp.presence.STATUS_INVISIBLE

    • summary
  • dojox.xmpp

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary