From 47a6cb2f8dcd84d9176551caae12de9b5fe88408 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Sat, 28 Nov 2009 23:18:55 +0100 Subject: [PATCH] Fix subject handling --- js/main.js | 51 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 14 deletions(-) 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') { -- 2.39.5