Index: openacs-4/packages/xotcl-core/tcl/bgdelivery-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-core/tcl/bgdelivery-procs.tcl,v diff -u -r1.49.2.3 -r1.49.2.4 --- openacs-4/packages/xotcl-core/tcl/bgdelivery-procs.tcl 30 Dec 2015 18:09:14 -0000 1.49.2.3 +++ openacs-4/packages/xotcl-core/tcl/bgdelivery-procs.tcl 1 Nov 2016 18:54:06 -0000 1.49.2.4 @@ -323,9 +323,12 @@ } Subscriber instproc send {msg} { + #ns_log notice "SEND <$msg> [my mode]" my log "" if {[my mode] eq "scripted"} { - set smsg "\n" set smsg [format %x [string length $smsg]]\r\n$smsg\r\n } else { @@ -376,17 +379,17 @@ fconfigure [my channel] -translation binary if {[my mode] eq "scripted"} { - set content_type text/html + set content_type "text/html;chartype=utf-8" set encoding "Cache-Control: no-cache\r\nTransfer-Encoding: chunked\r\n" set body "[string repeat { } 1024]\r\n" set body [format %x [string length $body]]\r\n$body\r\n } else { - #set content_type text/plain # Chrome refuses to expose partial response to ajax unless we - # set content_type to octet stream. Drawback is we now need to - # treat special characters on the client side. + # set content_type to octet stream. Drawback is we have to + # force the translation on the channel. set content_type "application/octet-stream" set encoding "" + fconfigure [my channel] -encoding utf-8 set body "" } Index: openacs-4/packages/xotcl-core/tcl/chat-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-core/tcl/Attic/chat-procs.tcl,v diff -u -r1.23.2.3 -r1.23.2.4 --- openacs-4/packages/xotcl-core/tcl/chat-procs.tcl 28 Oct 2016 18:57:36 -0000 1.23.2.3 +++ openacs-4/packages/xotcl-core/tcl/chat-procs.tcl 1 Nov 2016 18:54:06 -0000 1.23.2.4 @@ -14,7 +14,7 @@ user_id session_id {mode default} - {encoder urlencode} + {encoder noencode} {timewindow 600} {sweepinterval 599} {login_messages_p t} @@ -70,13 +70,6 @@ my instvar array now set user_id [expr {[info exists uid] ? $uid : [my set user_id]}] set color [my user_color $user_id] - # apisano: the vanilla chat you can include in a xowiki::Object - # page is not able to deliver messages like '%'. Usage by the chat - # package is fine, but probably something should be done to have a - # consistent quoting of special chars. This commented line is not - # ok, because would corrupt some chars in the chat package, which - # is our main usage. - # set msg [my encode $msg] set msg [ns_quotehtml $msg] # my log "-- msg=$msg" @@ -127,6 +120,9 @@ foreach {key value} [nsv_array get $array] { lassign $value timestamp secs user msg color if {$timestamp > $last} { + # + # add the message to the ordered composite. + # my add [Message new -time $secs -user_id $user -msg $msg -color $color] } else { my check_age $key [expr {($now - $timestamp) / 1000}] @@ -264,7 +260,7 @@ Chat instproc noencode {string} {set string} Chat instproc encode {string} {my [my encoder] $string} Chat instproc json_encode {string} { - string map [list \n \\n {"} {\"} ' {\'}] $string" + string map [list \n \\n \" \\\" ' {\'}] $string } Chat instproc json_encode_msg {msg} { @@ -278,91 +274,91 @@ return [subst -nocommands {{'messages': [ {'user':'$userlink', 'time': '$timeshort', 'msg':'$text'} ]\n} - }] - } + }] + } - Chat instproc js_encode_msg {msg} { - set json [my json_encode_msg $msg] - return "\n" - } + } - Chat instproc broadcast_msg {msg} { - my log "--chat broadcast_msg $msg" - ::xo::clusterwide \ - bgdelivery send_to_subscriber chat-[my chat_id] [my json_encode_msg $msg] - } + Chat instproc broadcast_msg {msg} { + my log "--chat broadcast_msg" + ::xo::clusterwide \ + bgdelivery send_to_subscriber chat-[my chat_id] [my json_encode_msg $msg] + } - Chat instproc subscribe {-uid} { - set user_id [expr {[info exists uid] ? $uid : [my set user_id]}] - set color [my user_color $user_id] - bgdelivery subscribe chat-[my chat_id] "" [my mode] - if {[my set login_messages_p] && ![my user_active $user_id]} { - # my broadcast_msg [Message new -volatile -time [clock seconds] \ - # -user_id $user_id -color $color \ - # -msg [_ xotcl-core.has_entered_the_room] ] - } - #my get_all - } + Chat instproc subscribe {-uid} { + set user_id [expr {[info exists uid] ? $uid : [my set user_id]}] + set color [my user_color $user_id] + bgdelivery subscribe chat-[my chat_id] "" [my mode] + if {[my set login_messages_p] && ![my user_active $user_id]} { + my broadcast_msg [Message new -volatile -time [clock seconds] \ + -user_id $user_id -color $color \ + -msg [_ xotcl-core.has_entered_the_room] ] + } + #my get_all + } - Chat instproc render {} { - my orderby time - set result "
\n" - foreach child [my children] { - set msg [$child msg] - set user_id [$child user_id] - set color [$child color] - set timelong [clock format [$child time]] - set timeshort [clock format [$child time] -format {[%H:%M:%S]}] - set userlink [my user_link -user_id $user_id -color $color] - - append result "

$timeshort " \ + Chat instproc render {} { + my orderby time + set result "

\n" + foreach child [my children] { + set msg [$child msg] + set user_id [$child user_id] + set color [$child color] + set timelong [clock format [$child time]] + set timeshort [clock format [$child time] -format {[%H:%M:%S]}] + set userlink [my user_link -user_id $user_id -color $color] + ns_log notice "encode <$msg> using encoder [my encoder] gives <[my encode $msg]>" + append result "

$timeshort " \ "$userlink " \ "[my encode $msg]

\n" - } - append result "
" - return $result - } + } + append result "
" + return $result + } - ############################################################################ - # Chat meta class, since we need to define general class-specific methods - ############################################################################ - Class create ChatClass -superclass ::xotcl::Class - ChatClass method sweep_all_chats {} { - my log "-- starting" - foreach nsv [nsv_names "[self]-*-seen"] { - if { [regexp "[self]-(\[0-9\]+)-seen" $nsv _ chat_id] } { - my log "--Chat_id $chat_id" - my new -volatile -chat_id $chat_id -user_id 0 -session_id 0 -init -sweeper - } - } - my log "-- ending" - } + ############################################################################ + # Chat meta class, since we need to define general class-specific methods + ############################################################################ + Class create ChatClass -superclass ::xotcl::Class + ChatClass method sweep_all_chats {} { + my log "-- starting" + foreach nsv [nsv_names "[self]-*-seen"] { + if { [regexp "[self]-(\[0-9\]+)-seen" $nsv _ chat_id] } { + my log "--Chat_id $chat_id" + my new -volatile -chat_id $chat_id -user_id 0 -session_id 0 -init -sweeper + } + } + my log "-- ending" + } - ChatClass method initialize_nsvs {} { - # read the last_activity information at server start into a nsv array - ::xo::dc foreach get_rooms { - select room_id, to_char(max(creation_date),'HH24:MI:SS YYYY-MM-DD') as last_activity - from chat_msgs group by room_id - } { - ::xo::clusterwide nsv_set [self]-$room_id-seen last [clock scan $last_activity] - } - } + ChatClass method initialize_nsvs {} { + # read the last_activity information at server start into a nsv array + ::xo::dc foreach get_rooms { + select room_id, to_char(max(creation_date),'HH24:MI:SS YYYY-MM-DD') as last_activity + from chat_msgs group by room_id + } { + ::xo::clusterwide nsv_set [self]-$room_id-seen last [clock scan $last_activity] + } + } - ChatClass method flush_messages {-chat_id:required} { - set array "[self]-$chat_id" - ::xo::clusterwide nsv_unset -nocomplain $array - ::xo::clusterwide nsv_unset -nocomplain $array-seen - ::xo::clusterwide nsv_unset -nocomplain $array-last-activity - } + ChatClass method flush_messages {-chat_id:required} { + set array "[self]-$chat_id" + ::xo::clusterwide nsv_unset -nocomplain $array + ::xo::clusterwide nsv_unset -nocomplain $array-seen + ::xo::clusterwide nsv_unset -nocomplain $array-last-activity + } - ChatClass method init {} { - # default setting is set19 from http://www.graphviz.org/doc/info/colors.html - # per parameter settings in the chat package are available (param UserColors) - my set colors [list #1b9e77 #d95f02 #7570b3 #e7298a #66a61e #e6ab02 #a6761d #666666] - } + ChatClass method init {} { + # default setting is set19 from http://www.graphviz.org/doc/info/colors.html + # per parameter settings in the chat package are available (param UserColors) + my set colors [list #1b9e77 #d95f02 #7570b3 #e7298a #66a61e #e6ab02 #a6761d #666666] + } } # 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.19 -r1.19.2.1 --- openacs-4/packages/xowiki/tcl/chat-procs.tcl 16 Jun 2015 19:49:20 -0000 1.19 +++ openacs-4/packages/xowiki/tcl/chat-procs.tcl 1 Nov 2016 18:54:06 -0000 1.19.2.1 @@ -119,7 +119,7 @@ error "mode $mode unknown, valid are: polling, streaming and scripted-streaming" } } - set send_url ${path}ajax/chat?m=add_msg&$context&msg= + set send_url ${path}ajax/chat?m=add_msg&$context&msg= if { ![file exists [acs_root_dir]/$jspath] } { return -code error "File [acs_root_dir]/$jspath does not exist" @@ -140,6 +140,8 @@ overflow:auto; } + template::add_body_script -script [subst {document.getElementById('chatMsg').focus();}] + switch $mode { polling {return "\ -
+
+
" Index: openacs-4/packages/xowiki/tcl/includelet-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/includelet-procs.tcl,v diff -u -r1.200.2.23 -r1.200.2.24 --- openacs-4/packages/xowiki/tcl/includelet-procs.tcl 14 Oct 2016 19:28:22 -0000 1.200.2.23 +++ openacs-4/packages/xowiki/tcl/includelet-procs.tcl 1 Nov 2016 18:54:06 -0000 1.200.2.24 @@ -4639,13 +4639,13 @@ } chat instproc render {} { my get_parameters - ns_log notice chat_id=$chat_id if {$chat_id eq ""} { # make the chat just for including page - set char_id [[my set __including_page] item_id] + set chat_id [[my set __including_page] item_id] } set r [::xowiki::Chat login -chat_id $chat_id -mode $mode -path $path] #ns_log notice chat=>$r + return $r } } 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.8.4.1 -r1.8.4.2 --- openacs-4/packages/xowiki/www/ajax/chat.tcl 10 Sep 2015 08:10:42 -0000 1.8.4.1 +++ openacs-4/packages/xowiki/www/ajax/chat.tcl 1 Nov 2016 18:54:06 -0000 1.8.4.2 @@ -5,10 +5,10 @@ @creation-date Jan 31, 2006 @cvs-id $Id$ } -query { - m - id + m:word + id:integer s - msg:optional + msg:optional,allhtml {mode ""} } Index: openacs-4/packages/xowiki/www/ajax/scripted-streaming-chat.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/ajax/Attic/scripted-streaming-chat.js,v diff -u -r1.4 -r1.4.4.1 --- openacs-4/packages/xowiki/www/ajax/scripted-streaming-chat.js 17 Feb 2013 11:48:06 -0000 1.4 +++ openacs-4/packages/xowiki/www/ajax/scripted-streaming-chat.js 1 Nov 2016 18:54:06 -0000 1.4.4.1 @@ -20,7 +20,7 @@ p.appendChild(span); span = document.createElement('span'); - span.innerHTML = decodeURI(unescape(data.messages[i].msg)); + span.innerHTML = data.messages[i].msg; span.className = 'message'; p.appendChild(span); @@ -32,14 +32,14 @@ function chatSendMsg() { var msg = document.getElementById('chatMsg').value; if (msg == '') { return; } - http_send.open('GET', send_url + encodeURIComponent(escape(msg)), true); + http_send.open('GET', send_url + encodeURIComponent(msg), true); http_send.onreadystatechange = function() { - if (http_send.readyState == 4) { - if (http_send.status != 200) { - alert('Something wrong in HTTP request, status code = ' + http_send.status); - } + if (http_send.readyState == 4) { + if (http_send.status != 200) { + alert('Something wrong in HTTP request, status code = ' + http_send.status); } + } }; http_send.send(null); document.getElementById('chatMsg').value = ''; -} \ No newline at end of file +} 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.8 -r1.8.4.1 --- openacs-4/packages/xowiki/www/ajax/streaming-chat.js 29 Jul 2013 08:56:44 -0000 1.8 +++ openacs-4/packages/xowiki/www/ajax/streaming-chat.js 1 Nov 2016 18:54:06 -0000 1.8.4.1 @@ -9,10 +9,11 @@ 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'); + //console.log('streaming chat has response'); + //console.log(response); var data = eval('(' + response + ')'); for (var i=0;i