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 += '<div class="msg">';
- if (sender) {
- if (body.search(/^\/me/) == 0) {
- body = body.replace(/^\/me/, sender);
- html += '<span class="sender">';
- html += body;
- html += '</span></div>';
+ if (body) {
+ if (sender) {
+ if (body.search(/^\/me/) == 0) {
+ body = body.replace(/^\/me/, sender);
+ html += '<span class="sender">';
+ html += body;
+ html += '</span></div>';
+ } else {
+ html += '<span class="sender">';
+ html += sender;
+ html += ':</span> ';
+ html += body + '</div>';
+ }
} else {
- html += '<span class="sender">';
- html += sender;
- html += ':</span> ';
- html += body + '</div>';
+ html += '<span class="server">';
+ html += body + '</span></div>';
}
- } else {
+ } else if (subject) {
html += '<span class="server">';
- html += body + '</span></div>';
+ html += "The subject is: " + subject + '</span></div>';
+ } else {
+ return true;
}
if (type == 'chat') {