From 128cf8cd245bfeb650d087d7c75c0ce0eab1fe1d Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Mon, 23 Mar 2009 00:13:51 +0100 Subject: [PATCH] Handle empty tune events (stopped listening to music) --- scripts/basic.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) 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; } -- 2.39.5