From: Florian Zeitz Date: Sun, 22 Mar 2009 23:13:51 +0000 (+0100) Subject: Handle empty tune events (stopped listening to music) X-Git-Url: https://git.babelmonkeys.de/?a=commitdiff_plain;h=128cf8cd245bfeb650d087d7c75c0ce0eab1fe1d;p=socialXMPP.git Handle empty tune events (stopped listening to music) --- diff --git a/scripts/basic.js b/scripts/basic.js index 06ff778..086729b 100644 --- a/scripts/basic.js +++ b/scripts/basic.js @@ -149,20 +149,26 @@ function _cbPEP(e) { // Handle Tune if (items.getAttribute('node') == NS_TUNE) { var tune = new Tune(); - 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]); - roster[jid2id(from)].tune = tune; - if ( $('#'+jid2id(from)+' .tune').length > 0 ) { - $('#'+jid2id(from)+' .tune').empty(); - $('#'+jid2id(from)+' .tune').append(Strophe.xmlTextNode('Listening to '+ tune.title + ' by ' + tune.artist + ' from ' + tune.source)); + 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 ( $('#'+jid2id(from)+' .tune').length > 0 ) { + $('#'+jid2id(from)+' .tune').empty(); + $('#'+jid2id(from)+' .tune').append(Strophe.xmlTextNode('Listening to '+ tune.title + ' by ' + tune.artist + ' from ' + tune.source)); + } else { + $('#'+jid2id(from)).append('
Listening to '+ tune.title + ' by ' + tune.artist + ' from ' + tune.source + ''); + } } else { - $('#'+jid2id(from)).append('
Listening to '+ tune.title + ' by ' + tune.artist + ' from ' + tune.source + ''); + if ( $('#'+jid2id(from)+' .tune').length > 0 ) { + $('#'+jid2id(from)+' .tune').empty(); + } } + roster[jid2id(from)].tune = tune; } return true; }