Commits

Ivan Vučica  committed 2abb95d

Displaying fulljid above roster. Work on adding presence subscriptions and roster additions, so ANONYMOUS auth can be useful.

  • Participants
  • Parent commits 61482ac

Comments (0)

Files changed (3)

-d967090b1162c6c2473ba7ef0e47e4bebafc968a zxmpp
+25bc818c11105671e887b12eeade85e6261cbaf0 zxmpp

File pong-network.js

 function pong_rosterRefresh()
 {
     var roster = "<div style='text-align: center;'><div style='height: 24px;'></div></div>";
+
+    roster += "<div style='font-family: sans-serif; font-size: 7pt; line-height: 30px; color: #333333; text-align: center;'>";
+    roster += this.zxmpp.bareJid;
+    roster += "</div>";
+
     var atLeastOneUserOnline = false;
     for(var jid in pong_rosterContent)
     {
     {
         roster += "<div style='text-align: center;'>noone online</div>";
     }
+
+    //roster += "<div style='text-align: center;'><input id='tvzpong-manualinvite' placeholder='jid@server.tld'><button onclick=\"pong_invite(document.getElementById('tvzpong-manualinvite').value, true)\">Direct invite</button></div>";
+    roster += "<div style='text-align: center;'><input id='tvzpong-addcontact' placeholder='jid@server.tld'><button onclick=\"pong_addContact(document.getElementById('tvzpong-addcontact').value, 'subscribe')\">Add contact</button></div>";
+
     document.getElementById('roster').innerHTML = roster;
 
 }
     for (var resource in presences)
     {
         var presence = presences[resource];
+
+        pong_reCap(jid + "/" + resource); // workaround for Z-XMPP bug where just-added entry's caps are incorrectly fetched.
+
         if(presence.caps && presence.caps.supports("http://tvzpong.vucica.net/protocol/"))
             supportsPong = true;
     }
 
 ////////////////////////////////
 var pong_talkTo = false;
-function pong_invite(jid)
+function pong_invite(jid, toBareJid)
 {
+    if(toBareJid)
+    {
+        pongInvitation_sendDemand(jid);
+        return;
+    }
     var resources = pong_rosterContactResourcesSupportingPong(jid);
     
     for(var resourceId in resources)
     }
 }
 
+function pong_addContact(bareJid, type)
+{
+    /* type: one of the following values: 'subscribe' or 'subscribed' */
+    {
+        var packet = new zxmpp.packet(zxmpp);
+        var iq = new zxmpp.stanzaIq(zxmpp);
+        iq.appendIqToPacket(packet, /* id */false, /* type */ "set", /* destination */ false, false);
+        var querynode = iq.appendQueryToPacket(packet, "jabber:iq:roster");
+
+        var itemnode = packet.xml.createElementNS("jabber:iq:roster", "item");
+        itemnode.setAttribute("jid", bareJid);
+        querynode.appendChild(itemnode);
+
+        packet.send("poll");
+    }
+    {
+        var packet = new zxmpp.packet(zxmpp);
+        var presence = new zxmpp.stanzaPresence(zxmpp);
+        presence.appendToPacket(packet, /* from *//*false*/zxmpp.fullJid, /* to */ bareJid, /* show */ "avail", /*status*/ false, /*priority*/false, /*type*/ type );
+
+        console.log(packet);
+
+        packet.send("poll");
+    }
+
+//    if(!pong_rosterContent[bareJid])
+//        pong_rosterAdded(bareJid, "available", false, false);
+//    else
+//        {} // do nothing, we don't want to overwrite existing entry
+}
+
+function pong_reCap(fullJid)
+{
+    return;// DISABLING THIS CODE
+    var presence = zxmpp.getPresence(fullJid);
+    if(!fullJid || !fullJid.split)
+    {
+        console.error("Fulljid in pong_reCap() is not a string");
+        cosnole.error(fullJid);
+        return;
+    }
+    if(fullJid.split("/").length == 1)
+    {
+        console.error("Cannot recap barejid: " + fullJid);
+        return;
+    }
+    if(presence && presence.caps && presence.caps.ext)
+    {
+        console.log("Want to get " + presence.caps.ext);
+        var exts = presence.caps.ext.split(" ");
+        for(var extId in exts)
+        {
+            console.log("==> FETCHING " + exts[extId] + " FOR " + fullJid);
+            presence.caps.unpackExt(exts[extId]);
+        }
+    }
+}
 ///////////////////////////////
 
 function pongZXMPP_onConnectionTerminate(sender, code, humanreadable)
     pongNotification_show("Disconnected.\n\nReason: " + humanreadable + "\n\nCode: " + code);
 }
 
-function pongZXMPP_onPresenceUpdate(sender, presence)
+function pongZXMPP_onPresenceUpdate(sender, presence, stanza)
 {
     var topPresence = sender.getTopPresenceForBareJid(presence.bareJid);
     if(topPresence)
         
         if(!pong_rosterContent[topPresence.bareJid])
         {
-            //console.warn("!!!!! NO ROSTER ENTRY FOR " + topPresence.bareJid);
-            // Happens when getting report for ourselves.
+            if(topPresence.bareJid != sender.bareJid) 
+            {
+                if(stanza.type == 'subscribe')
+                {
+                    if(confirm("You were added as a contact by \n   " + presence.bareJid + "\n\nAdd back?"))
+                    {
+                        console.log("Adding back: " + presence.bareJid);
+                        pong_addContact(presence.bareJid, "subscribed");
+                    }
+                    else
+                    {
+                        console.log("Not adding back: " + presence.bareJid);
+                        pong_addContact(presence.bareJid, "unsubscribed");
+                    }
+                }
+                else if (stanza.type == "subscribed")
+                {
+                    pong_reCap(presence.fullJid);
+                }
+                else
+                {
+                    console.warn("!!!!! NO ROSTER ENTRY FOR " + topPresence.bareJid);
+                    console.log(presence);
+                }
+
+            }
+            else
+            {
+                // Not a problem if getting the report for ourselves.
+            }
         }
         else
         {
                 display = vcard.fn;
             
             pong_rosterAdded(item.bareJid, presenceShow, display, presenceStatus);
-        }
-        
-        
+
+            if(presence.fullJid)
+                pong_reCap(presence.fullJid);
+            
+        }        
     }
     else
     {
 {
     margin-left: auto;
     margin-right: auto;
-    width: 100px;
+    width: 350px;
     display: none;
 }
 .roster div.contact