]> git.babelmonkeys.de Git - socialXMPP.git/commitdiff
Make PEP support a bit more flexible
authorFlorian Zeitz <florob@babelmonkeys.de>
Tue, 25 Aug 2009 14:42:47 +0000 (16:42 +0200)
committerFlorian Zeitz <florob@babelmonkeys.de>
Tue, 25 Aug 2009 14:42:47 +0000 (16:42 +0200)
* PEP callback now calls external functions

scripts/basic.js

index 4b306950714a66569ba9b888097a2b0ed55d4f51..fbb8d859f5d33db21c200164c9a53856dc7f90f5 100644 (file)
@@ -277,6 +277,33 @@ function genCaps() {
     return b64_sha1(S);
 }
 
+function handleTune(jid, tuneXML) {
+    var tune = new Tune();
+    if (tuneXML.childNodes.length > 0) {
+       tune.artist = Strophe.getText(tuneXML.getElementsByTagName('artist')[0]);
+       tune.length= Strophe.getText(tuneXML.getElementsByTagName('length')[0]);
+       tune.rating= Strophe.getText(tuneXML.getElementsByTagName('rating')[0]);
+       tune.source= Strophe.getText(tuneXML.getElementsByTagName('source')[0]);
+       tune.title= Strophe.getText(tuneXML.getElementsByTagName('title')[0]);
+       tune.track= Strophe.getText(tuneXML.getElementsByTagName('track')[0]);
+       tune.uri= Strophe.getText(tuneXML.getElementsByTagName('uri')[0]);
+       if (roster[jid2id(jid)].visible == true) {
+           if ( $('#tune').length > 0) {
+               $('#tune').empty();
+               $('#tune').append('<span class="vCardName">Tune: </span>');
+               $('#tune').append(Strophe.xmlTextNode('Listening to '+ tune.title +
+                       ' by ' + tune.artist + ' from ' + tune.source));
+           } else {
+               $('#vCard ul').append('<li id="tune"><span class="vCardName">Tune: </span>Listening to '+ tune.title +
+                       ' by ' + tune.artist + ' from ' + tune.source + '</li>')
+           }
+       }
+    } else {
+       $('#tune').remove();
+    }
+    roster[jid2id(jid)].tune = tune;
+}
+
 function _cbPEP(e) {
     var from = e.getAttribute('from');
     if (Strophe.getBareJidFromJid(from) == Strophe.getBareJidFromJid(connection.jid)) {
@@ -285,30 +312,7 @@ function _cbPEP(e) {
     var items = e.getElementsByTagName('items')[0];
     // Handle Tune
     if (items.getAttribute('node') == NS_TUNE) {
-       var tune = new Tune();
-       if (items.getElementsByTagName('tune')[0].childNodes.length > 0) {
-           tune.artist = Strophe.getText(items.getElementsByTagName('artist')[0]);
-           tune.length= Strophe.getText(items.getElementsByTagName('length')[0]);
-           tune.rating= Strophe.getText(items.getElementsByTagName('rating')[0]);
-           tune.source= Strophe.getText(items.getElementsByTagName('source')[0]);
-           tune.title= Strophe.getText(items.getElementsByTagName('title')[0]);
-           tune.track= Strophe.getText(items.getElementsByTagName('track')[0]);
-           tune.uri= Strophe.getText(items.getElementsByTagName('uri')[0]);
-           if (roster[jid2id(from)].visible == true) {
-               if ( $('#tune').length > 0) {
-                   $('#tune').empty();
-                   $('#tune').append('<span class="vCardName">Tune: </span>');
-                   $('#tune').append(Strophe.xmlTextNode('Listening to '+ tune.title +
-                               ' by ' + tune.artist + ' from ' + tune.source));
-               } else {
-                   $('#vCard ul').append('<li id="tune"><span class="vCardName">Tune: </span>Listening to '+ tune.title +
-                               ' by ' + tune.artist + ' from ' + tune.source + '</li>')
-               }
-           }
-       } else {
-           $('#tune').remove();
-       }
-       roster[jid2id(from)].tune = tune;
+       handleTune(from, items.getElementsByTagName('tune')[0]);
     }
     return true;
 }