From 43e0a653ab9ef78eb9b4e5e76dc615d2f3b72596 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Thu, 9 Apr 2009 21:17:24 +0200 Subject: [PATCH] Basic message receiving support --- css/standard.css | 4 ++++ scripts/basic.js | 24 +++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/css/standard.css b/css/standard.css index 31a1782..1792f53 100644 --- a/css/standard.css +++ b/css/standard.css @@ -39,3 +39,7 @@ max-width: 70px; max-height: 70px; } + +.sender { + color: blue; +} diff --git a/scripts/basic.js b/scripts/basic.js index 934308c..4fb36fa 100644 --- a/scripts/basic.js +++ b/scripts/basic.js @@ -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, '
'); + body = body.replace(/%3C/g, '<'); + body = body.replace(/%3E/g, '>'); + body = body.replace(/%26/g, '&'); + body = unescape(body); + if ($('#' + id).length > 0) { + $('#' + id + ' p').append('
'); + $('#' + id + ' p').append('' + jid + ': '); + $('#' + id + ' p').append(body); + } else { + $('body').append('

' + jid + ': ' + body + '

'); + } + + 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(); -- 2.39.5