X-Git-Url: http://cgit.babelmonkeys.de/?p=xmppchat.git;a=blobdiff_plain;f=js%2Fmain.js;h=7dbe8e5999c52042a9731da9467a7680b9dd6c68;hp=6072c6704f404a13ae48428c9fb0aefe1e5a5e6c;hb=47a6cb2f8dcd84d9176551caae12de9b5fe88408;hpb=b05a99e9f93f553586cc4210d4cc79caa174f1e0 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') {