]> cgit.babelmonkeys.de Git - socialXMPP.git/commitdiff
Basic message receiving support
authorFlorian Zeitz <florob@babelmonkeys.de>
Thu, 9 Apr 2009 19:17:24 +0000 (21:17 +0200)
committerFlorian Zeitz <florob@babelmonkeys.de>
Thu, 9 Apr 2009 19:17:24 +0000 (21:17 +0200)
css/standard.css
scripts/basic.js

index 31a1782e0528ca635fdc487c91236780a667db5f..1792f53c2166572d35a5d50d642d04791e67c1ab 100644 (file)
@@ -39,3 +39,7 @@
   max-width: 70px;
   max-height: 70px;
 }
+
+.sender {
+  color: blue;
+}
index 934308c22fc1fc413305f34911545322d563514f..4fb36fab946d6c3cbf94002baaa0601b88f267d1 100644 (file)
@@ -127,7 +127,6 @@ function getVCard(jid) {
     } else {
        _cbVCard(roster[jid2id(jid)].vCard);
     }
-
 }
 
 function getOwnInfo() {
@@ -191,6 +190,27 @@ function _cbDisco(e) {
     return true;
 }
 
+function _cbMessage(msg) {
+    var jid = $(msg).attr('from');
+    var id = jid2id($(msg).attr('from')) + 'Chat';
+    var body = $(msg).find('body:first').text();
+    body = escape(body);
+    body = body.replace(/%0A/g, '<br/>');
+    body = body.replace(/%3C/g, '&lt;');
+    body = body.replace(/%3E/g, '&gt;');
+    body = body.replace(/%26/g, '&amp;');
+    body = unescape(body);
+    if ($('#' + id).length > 0) {
+       $('#' + id + ' p').append('<br/>');
+       $('#' + id + ' p').append('<span class="sender">' + jid + ': </span>');
+       $('#' + id + ' p').append(body);
+    } else {
+       $('body').append('<div class="chat" id="' + id + '"><p><span class="sender">' + jid + ': </span>' + body + '</p></div>');
+    }
+
+    return true;
+}
+
 function genCaps() {
     var S = '';
     S += 'client/web//' + appName + '<'
@@ -252,6 +272,7 @@ function onConnect(status) {
        getOwnInfo();
        getRoster();
        connection.addHandler(_cbDisco, Strophe.NS.DISCO_INFO, 'iq', 'get');
+       connection.addHandler(_cbMessage, Strophe.NS.CLIENT, 'message');
     }
 }
 
@@ -264,6 +285,7 @@ function showConnect() {
     $('#ownInfo').hide();
     $('#vCard_container').empty();
     $('#friends').empty();
+    $('.chat').remove();
     $('label').show();
     jid.show();
     pass.show();