Index: openacs-4/packages/xowiki/tcl/chat-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/chat-procs.tcl,v diff -u -r1.16 -r1.17 --- openacs-4/packages/xowiki/tcl/chat-procs.tcl 17 Feb 2013 11:48:06 -0000 1.16 +++ openacs-4/packages/xowiki/tcl/chat-procs.tcl 29 Jul 2013 08:56:44 -0000 1.17 @@ -6,42 +6,49 @@ @cvs-id $Id$ } namespace eval ::xowiki { - ::xo::ChatClass Chat -superclass ::xo::Chat + ::xo::ChatClass create Chat -superclass ::xo::Chat - Chat instproc render {} { - my orderby time - set result "" - foreach child [my children] { - set msg [$child msg] - set user_id [$child user_id] - set timelong [clock format [$child time]] - set timeshort [clock format [$child time] -format {[%H:%M:%S]}] - if {$user_id > 0} { - acs_user::get -user_id $user_id -array user - set name [expr {$user(screen_name) ne "" ? $user(screen_name) : $user(name)}] - set url "/shared/community-member?user%5fid=$user_id" - set creator "$name" - } else { - set creator "Nobody" - } - append result "$timeshort\ - [my encode $creator]\ - [my encode $msg]\n" - } - return $result - } + # Chat instproc render {} { + # my orderby time + # set result "" + # foreach child [my children] { + # set msg [$child msg] + # set user_id [$child user_id] + # set timelong [clock format [$child time]] + # set timeshort [clock format [$child time] -format {[%H:%M:%S]}] + # if {$user_id > 0} { + # acs_user::get -user_id $user_id -array user + # set name [expr {$user(screen_name) ne "" ? $user(screen_name) : $user(name)}] + # set url "/shared/community-member?user%5fid=$user_id" + # set creator "$name" + # } else { + # set creator "Nobody" + # } + # append result "$timeshort\ + # [my encode $creator]\ + # [my encode $msg]\n" + # } + # return $result + # } Chat proc initialize_nsvs {} {;} ;# noop - Chat proc login {-chat_id -package_id -mode} { + Chat proc login {-chat_id -package_id {-mode ""} {-path ""}} { #my log "--chat" + if {![ns_conn isconnected]} return auth::require_login if {![info exists package_id]} {set package_id [ad_conn package_id] } if {![info exists chat_id]} {set chat_id $package_id } - set context id=$chat_id&s=[ad_conn session_id].[clock seconds] - set path [lindex [site_node::get_url_from_object_id -object_id $package_id] 0] + set session_id [ad_conn session_id].[clock seconds] + set context id=$chat_id&s=$session_id + #my log "chat_id=$chat_id, path=$path" + if {$path eq ""} { + set path [lindex [site_node::get_url_from_object_id -object_id $package_id] 0] + } elseif {[string range $path end end] ne "/"} { + append path / + } - if {![info exists mode]} { + if {$mode eq ""} { # # The parameter "mode" was not specified, we try to guess the # "best" mode known to work for the currently used browser. @@ -108,6 +115,9 @@ set jspath packages/xowiki/www/ajax/scripted-streaming-chat.js set subscribe_url ${path}ajax/chat?m=subscribe&$context } + default { + error "mode $mode unknown, valid are: polling, streaming and scripted-streaming" + } } set send_url ${path}ajax/chat?m=add_msg&$context&msg= @@ -118,6 +128,18 @@ my log "--CHAT mode=$mode" + set style { + margin:1.5em 0 1.5em 0; + padding:1em 0 1em 1em; + background-color: #f9f9f9; + border:1px solid #dedede; + height:150px; + font-size:.95em; + line-height:.7em; + color:#333; + overflow:auto; + } + switch $mode { polling {return "\ -
+
$r
" } - scripted-streaming {return "\ + scripted-streaming { + ::xowiki::Chat create c1 -destroy_on_cleanup -chat_id $chat_id -session_id $session_id -mode $mode + set r [ns_urldecode [c1 get_all]] + regsub -all {<[/]?div[^>]*>} $r "" r + return "\ -
+
Index: openacs-4/packages/xowiki/www/ajax/chat.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/ajax/Attic/chat.js,v diff -u -r1.7 -r1.8 --- openacs-4/packages/xowiki/www/ajax/chat.js 17 Feb 2013 11:48:06 -0000 1.7 +++ openacs-4/packages/xowiki/www/ajax/chat.js 29 Jul 2013 08:56:44 -0000 1.8 @@ -17,43 +17,24 @@ } function appendToMessages(content) { - var xmlobject = (new DOMParser()).parseFromString(content, 'application/xhtml+xml'); - var items = xmlobject.getElementsByTagName('TR'); - //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); + var xmlobject = (new DOMParser()).parseFromString(content, 'application/xhtml+xml'); + var items = xmlobject.getElementsByTagName('div')[0].children; - //if (items.length > 0) {alert('appending ' + content);} - var doc = frames['ichat'].document; - var tbody = frames['ichat'].document.getElementById('messages').tBodies[0]; - //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; - for (var i = 0 ; i < items.length ; i++) { - tr = doc.createElement('tr'); - e = items[i].getElementsByTagName('TD'); - td = doc.createElement('td'); - td.innerHTML = decodeURIComponent(e[0].firstChild.nodeValue); - td.className = 'timestamp'; - tr.appendChild(td); + //console.debug("items: " + items.length); + //if (items.length > 0) {console.log(content);} + //if (items.length > 0) {console.log(items[0].innerHTML);} - td = doc.createElement('td'); - s = e[1].firstChild.nodeValue; - td.innerHTML = decodeURIComponent(e[1].firstChild.nodeValue.replace(/\+/g,' ')); - td.className = 'user'; - tr.appendChild(td); - - td = doc.createElement('td'); - td.innerHTML = decodeURIComponent(e[2].firstChild.nodeValue.replace(/\+/g,' ')); - td.className = 'message'; - tr.appendChild(td); - - tbody.appendChild(tr); - } - frames['ichat'].window.scrollTo(0,tbody.offsetHeight); + var doc = frames['ichat'].document; + var messages = frames['ichat'].document.getElementsByTagName('div')[0]; + for (var i = 0 ; i < items.length ; i++) { + var p = doc.createElement('p'); // add class 'line' + var att = doc.createAttribute("class"); + att.value = 'line'; + p.setAttributeNode(att); + p.innerHTML = decodeURIComponent(items[i].innerHTML).replace(/\+/g,' '); + messages.appendChild(p); + } + frames['ichat'].window.scrollTo(0,messages.offsetHeight); } Index: openacs-4/packages/xowiki/www/ajax/chat.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/ajax/Attic/chat.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/xowiki/www/ajax/chat.tcl 13 Sep 2012 16:05:34 -0000 1.7 +++ openacs-4/packages/xowiki/www/ajax/chat.tcl 29 Jul 2013 08:56:44 -0000 1.8 @@ -13,7 +13,7 @@ } #ns_log notice "--chat m=$m session_id=$s [clock format [lindex [split $s .] 1] -format %H:%M:%S] mode=$mode" -::xowiki::Chat c1 -volatile -chat_id $id -session_id $s -mode $mode +::xowiki::Chat create c1 -destroy_on_cleanup -chat_id $id -session_id $s -mode $mode switch -- $m { add_msg { #ns_log notice "--c call c1 $m '$msg'" @@ -27,14 +27,25 @@ default {ns_log error "--c unknown method $m called."} } +#ns_log notice "--chat.tcl $m: returns '$_'" + +set style { + padding:1em 0 1em 1em; + background-color: #f9f9f9; + font-size:.95em; + color:#333; + overflow:auto; +} + ns_return 200 text/html " -$_
+$_ " Index: openacs-4/packages/xowiki/www/ajax/streaming-chat.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/ajax/Attic/streaming-chat.js,v diff -u -r1.7 -r1.8 --- openacs-4/packages/xowiki/www/ajax/streaming-chat.js 17 Feb 2013 11:48:06 -0000 1.7 +++ openacs-4/packages/xowiki/www/ajax/streaming-chat.js 29 Jul 2013 08:56:44 -0000 1.8 @@ -9,6 +9,7 @@ function getData() { //alert('access responseText'); // hmm, IE does not allow us to access responstext in state == 3 :( var response = http.responseText.substring(http_last); + console.log(response); // we recognize a complete message by a trailing }\n if (response.match(/\}[\n ]+$/)) { var messages = document.getElementById('messages'); @@ -56,16 +57,18 @@ } function chatSubscribe(subscribe_url) { + console.log("chatSubscribe " + subscribe_url); http.open('GET', subscribe_url, true); http.onreadystatechange = function() { if (http.readyState == 3) { - getData(); + getData(); } else if (http.readyState == 4) { + //console.log("chatSubscribe readyState = " + http.readyState + " status " + http.status); // alert('status code =' + http.status); var status = http.status; if (status == 200 || status == 0) { - document.getElementById('chatMsg').value = 'logout'; - chatSendMsg(); + //document.getElementById('chatMsg').value = 'logout'; + //chatSendMsg(); } else { alert('Something wrong in HTTP request, status code = ' + status); }