Index: openacs-4/packages/chat/tcl/chat-ajax-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/tcl/chat-ajax-procs.tcl,v diff -u -N -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/chat/tcl/chat-ajax-procs.tcl 30 Mar 2006 09:15:12 -0000 1.1.2.1 +++ openacs-4/packages/chat/tcl/chat-ajax-procs.tcl 31 Mar 2006 12:52:48 -0000 1.1.2.2 @@ -3,6 +3,7 @@ @creation-date 2006-02-02 @author Gustaf Neumann + @author Peter Alberer @cvs-id $Id$ } @@ -20,22 +21,16 @@ return -code error "File [acs_root_dir]/$path does not exist" } set file [open [acs_root_dir]/$path]; set js [read $file]; close $file - #set location [util_current_location] set path [site_node::get_url_from_object_id -object_id $package_id] set login_url $path/ajax/chat?m=login&$context set send_url $path/ajax/chat?m=add_msg&$context&msg= - set users_url $path/ajax/users?m=login&$context - #set get_update "chatUpdateData()" - #chatSendCmd(\"$path/ajax/chat?m=get_new&$context\",chatReceiver)" - set get_userlist "chatUpdateUserList(\"$users_url\",usersReceiver)" - #set get_all "chatSendCmd(\"$path/ajax/chat?m=get_all&$context\",chatReceiver)" + set users_url $path/ajax/chat?m=get_users&$context return "\ Index: openacs-4/packages/chat/www/ajax/chat.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/ajax/Attic/chat.js,v diff -u -N -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/chat/www/ajax/chat.js 30 Mar 2006 09:15:13 -0000 1.1.2.1 +++ openacs-4/packages/chat/www/ajax/chat.js 31 Mar 2006 12:52:49 -0000 1.1.2.2 @@ -1,8 +1,8 @@ // small cross browser function to get an HTTP object for making // AJAX style http requests in the background // -gustaf neumann Jan, 2006 -// exended for dotlrn-chat and listing of users -// -peter alberer +// exended for dotlrn-chat, message coloring and listing of users +// -peter alberer March, 2006 // global variables var msgcount = 0; // hack to overcome IE @@ -44,91 +44,94 @@ } // functions that handle the incoming xml/html data -function messagesReceiver(content) { - var xmlobject = (new DOMParser()).parseFromString(content, 'application/xhtml+xml'); - var items = xmlobject.getElementsByTagName('p'); - // alert('found ' + items.length + ' items'); - - //var counter = document.getElementById('chatCounter'); - //counter.innerHTML = parseInt(counter.innerHTML) + 1; - //document.getElementById('chatResponse').innerHTML = 'items = ' + items.length + ' l=' + content.length + ' ' + escape(content); - - //if (items.length > 0) {alert('appending ' + content);} - var doc = frames['ichat'].document; - var div = frames['ichat'].document.getElementById('messages'); - //var tbody = tbodies[tbodies.length -1]; - //for (var i = 0 ; i < items.length ; i++) { - // tbody.appendChild(frames['ichat'].document.importNode(items[i],true)); - //} - var tr, td, e, s; - var msgCount = 0; - for (var i = 0 ; i < items.length ; i++) { - msgCount++; - // tbody.appendChild(items[i]); - p = doc.createElement('p'); - p.className = 'line'; - e = items[i].getElementsByTagName('span'); - span = doc.createElement('span'); - span.innerHTML = decodeURIComponent(e[0].firstChild.nodeValue); - span.className = 'timestamp'; - p.appendChild(span); - - span = doc.createElement('span'); - s = e[1].firstChild.nodeValue; - span.innerHTML = decodeURIComponent(e[1].firstChild.nodeValue.replace(/\+/g,' ')); - span.className = 'user'; - p.appendChild(span); - - span = doc.createElement('span'); - span.innerHTML = decodeURIComponent(e[2].firstChild.nodeValue.replace(/\+/g,' ')); - span.className = 'message'; - p.appendChild(span); - - div.appendChild(p); - } - if ( msgCount > 0 ) { - frames['ichat'].window.scrollTo(0,div.offsetHeight); - } +function messagesReceiver(node,doc,div) { + var tr, td, e, s; + var msgCount = 0; + for (var i = 0 ; i < node.childNodes.length ; i++) { + if (node.childNodes[i].nodeType == 3 ){ + // if this is a textnode, skip it + continue; + } + msgCount++; + p = doc.createElement('p'); + p.className = 'line'; + e = node.childNodes[i].getElementsByTagName('span'); + span = doc.createElement('span'); + span.innerHTML = decodeURIComponent(e[0].firstChild.nodeValue); + span.className = 'timestamp'; + p.appendChild(span); + + span = doc.createElement('span'); + s = e[1].firstChild.nodeValue; + span.innerHTML = decodeURIComponent(e[1].firstChild.nodeValue.replace(/\+/g,' ')); + span.className = 'user'; + p.appendChild(span); + + span = doc.createElement('span'); + span.innerHTML = decodeURIComponent(e[2].firstChild.nodeValue.replace(/\+/g,' ')); + span.className = 'message'; + p.appendChild(span); + + div.appendChild(p); + } + if ( msgCount > 0 ) { + frames['ichat'].window.scrollTo(0,div.offsetHeight); + } } function pushReceiver(content) { - messagesReceiver(content); + updateReceiver(content); var msgField = document.getElementById('chatMsg'); msgField.value = ''; msgField.disabled = false; msgField.focus(); } -function usersReceiver(content) { - var xmlobject = (new DOMParser()).parseFromString(content, 'application/xhtml+xml'); - var items = xmlobject.getElementsByTagName('TR'); - var doc = frames['ichat-users'].document; - var tbody = frames['ichat-users'].document.getElementById('users').tBodies[0]; - var tr, td, e, s, nbody; - - nbody = doc.createElement('tbody'); - - for (var i = 0 ; i < items.length ; i++) { - tr = doc.createElement('tr'); - e = items[i].getElementsByTagName('TD'); +function updateReceiver(content) { + var xmlobject = (new DOMParser()).parseFromString(content, 'application/xhtml+xml'); + var body = xmlobject.getElementsByTagName('body'); - td = doc.createElement('td'); - td.innerHTML = decodeURIComponent(e[0].firstChild.nodeValue.replace(/\+/g,' ')); - td.className = 'user'; - tr.appendChild(td); + var usersNode = body[0].childNodes[1].childNodes[0]; + if (usersNode.hasChildNodes()) { + var usersDoc = frames['ichat-users'].document; + var usersTbody = frames['ichat-users'].document.getElementById('users').tBodies[0]; + usersReceiver(usersNode,usersDoc,usersTbody); + } - td = doc.createElement('td'); - td.innerHTML = decodeURIComponent(e[1].firstChild.nodeValue.replace(/\+/g,' ')); - td.className = 'timestamp'; - tr.appendChild(td); - - nbody.appendChild(tr); - } - - tbody.parentNode.replaceChild(nbody,tbody); - + var messagesNode = body[0].childNodes[0]; + if (messagesNode.hasChildNodes()) { + var messagesDoc = frames['ichat'].document; + var messagesDiv = frames['ichat'].document.getElementById('messages'); + messagesReceiver(messagesNode,messagesDoc,messagesDiv); + } } +function usersReceiver(node,doc,tbody) { + var tr, td, e, s, nbody; + nbody = doc.createElement('tbody'); + for (var i = 0 ; i < node.childNodes.length ; i++) { + if (node.childNodes[i].nodeType == 3 ){ + // if this is a textnode, skip it + continue; + } + tr = doc.createElement('tr'); + e = node.childNodes[i].getElementsByTagName('TD'); + + td = doc.createElement('td'); + td.innerHTML = decodeURIComponent(e[0].firstChild.nodeValue.replace(/\+/g,' ')); + td.className = 'user'; + tr.appendChild(td); + + td = doc.createElement('td'); + td.innerHTML = decodeURIComponent(e[1].firstChild.nodeValue.replace(/\+/g,' ')); + td.className = 'timestamp'; + tr.appendChild(td); + + nbody.appendChild(tr); + } + tbody.parentNode.replaceChild(nbody,tbody); +} + function DataConnection() {}; DataConnection.prototype = { @@ -189,9 +192,11 @@ updateBackground: function() { //alert("binda = " + this); if (this.busy) { - alert("Message update function cannot run because the last connection is still busy!"); + //alert("Message update function cannot run because the last connection is still busy!"); + return; + } else { + this.httpSendCmd(this.url); } - this.httpSendCmd(this.url); } } @@ -209,6 +214,7 @@ function updateDataConnections() { for (var ds in dataConnections) { if (dataConnections[ds].autoConnect) { + // alert("updating " + dataConnections[ds].url); dataConnections[ds].updateBackground(); } } Index: openacs-4/packages/chat/www/ajax/chat.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/ajax/Attic/chat.tcl,v diff -u -N -r1.1.2.1 -r1.1.2.2 --- openacs-4/packages/chat/www/ajax/chat.tcl 30 Mar 2006 09:15:13 -0000 1.1.2.1 +++ openacs-4/packages/chat/www/ajax/chat.tcl 31 Mar 2006 12:52:49 -0000 1.1.2.2 @@ -11,23 +11,35 @@ {msg ""} } +set message_output "" +set user_output "" + ::chat::Chat c1 -volatile -chat_id $id -session_id $s switch -- $m { add_msg { + # do not allow messages longer than 200 characters if { [string length $msg] > 200 } { set msg [string range $msg 0 200] } - set _ [c1 $m $msg] - - set user_id [ad_conn user_id] - chat_message_post $id $user_id $msg f - - # ns_log notice "--c add_msg returns '$_' -chat_id:$id -session_id:$s msg:$msg m:$m" + # do not insert empty messages, if they managed to get here + if { $msg ne "" } { + set message_output [c1 $m $msg] + set user_id [ad_conn user_id] + chat_message_post $id $user_id $msg f + } } - login - - get_new - - get_all {set _ [c1 $m]} + login - get_new - get_all { + set message_output [c1 $m] + } + get_updates { + set message_output [c1 get_new] + set user_output [c1 get_users] + } + get_users { + c1 encoder noencode + set user_output [c1 get_users] + } default {ns_log error "--c unknown method $m called."} } @@ -39,8 +51,9 @@ #messages .user {margin: 0px 5px; text-align: right; vertical-align: top; font-weight:bold;} #messages .message {vertical-align: top;} #messages .line {margin:0px;} +#users { width: 100%; font-size: 12px; color: #666666; font-family: Trebuchet MS, Lucida Grande, Lucida Sans Unicode, Arial, sans-serif; } +#users .user {text-align: left; vertical-align: top; font-weight:bold; } +#users .timestamp {text-align: right; vertical-align: top; } - -
$_
- +
$message_output
$user_output
" \ No newline at end of file Index: openacs-4/packages/chat/www/ajax/users.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/ajax/Attic/users.tcl,v diff -u -N --- openacs-4/packages/chat/www/ajax/users.tcl 31 Mar 2006 09:26:28 -0000 1.1.2.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,34 +0,0 @@ -ad_page_contract { - realtime user list for a chat room - - @author Peter Alberer (peter.alberer@wu-wien.ac.at) - @creation-date Mar 10, 2006 -} -query { - id - s - {m:optional "update"} -} -#after 1000 -::chat::Chat c1 -volatile -chat_id $id -session_id $s - -if { $m eq "login" } { c1 encoder noencode } -set output "" -foreach {user_id timestamp} [c1 active_user_list] { - if {$user_id > 0} { - set diff [clock format [expr {[clock seconds] - $timestamp}] -format "%H:%M:%S" -gmt 1] - set userlink [c1 user_link -user_id $user_id] - append output "$userlink$diff\n" - } -} - -ns_return 200 text/html " - - - -$output
- -"