From: Florian Zeitz Date: Sat, 28 Nov 2009 22:18:55 +0000 (+0100) Subject: Fix subject handling X-Git-Url: https://git.babelmonkeys.de/?a=commitdiff_plain;h=47a6cb2f8dcd84d9176551caae12de9b5fe88408;p=xmppchat.git Fix subject handling --- diff --git a/js/main.js b/js/main.js index 6072c67..7dbe8e5 100644 --- a/js/main.js +++ b/js/main.js @@ -72,26 +72,49 @@ function addBubble(nick) { function handleMessage(msg) { var html = ''; - var sender = Strophe.xmlescape(Strophe.getResourceFromJid(msg.getAttribute('from'))); + var sender = Strophe.getResourceFromJid(msg.getAttribute('from')); + if (sender) { + sender = Strophe.xmlescape(sender); + } else { + sender = false; + } var type = msg.getAttribute('type'); - var body = Strophe.xmlescape(Strophe.getText(msg.getElementsByTagName('body')[0])); + var body = msg.getElementsByTagName('body')[0]; + if (body) { + body = Strophe.xmlescape(Strophe.getText(body)); + } else { + body = false; + } + var subject = msg.getElementsByTagName('subject')[0]; + if (subject) { + subject = Strophe.xmlescape(Strophe.getText(subject)); + } else { + subject = false; + } html += '
'; - if (sender) { - if (body.search(/^\/me/) == 0) { - body = body.replace(/^\/me/, sender); - html += ''; - html += body; - html += '
'; + if (body) { + if (sender) { + if (body.search(/^\/me/) == 0) { + body = body.replace(/^\/me/, sender); + html += ''; + html += body; + html += ''; + } else { + html += ''; + html += sender; + html += ': '; + html += body + ''; + } } else { - html += ''; - html += sender; - html += ': '; - html += body + ''; + html += ''; + html += body + ''; } - } else { + } else if (subject) { html += ''; - html += body + ''; + html += "The subject is: " + subject + ''; + } else { + return true; } if (type == 'chat') {