]> git.babelmonkeys.de Git - xmppchat.git/commitdiff
Fix subject handling
authorFlorian Zeitz <florob@babelmonkeys.de>
Sat, 28 Nov 2009 22:18:55 +0000 (23:18 +0100)
committerFlorian Zeitz <florob@babelmonkeys.de>
Sat, 28 Nov 2009 22:18:55 +0000 (23:18 +0100)
js/main.js

index 6072c6704f404a13ae48428c9fb0aefe1e5a5e6c..7dbe8e5999c52042a9731da9467a7680b9dd6c68 100644 (file)
@@ -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 += '<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') {