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.1 -r1.2 --- openacs-4/packages/xowiki/tcl/chat-procs.tcl 3 Feb 2006 22:17:41 -0000 1.1 +++ openacs-4/packages/xowiki/tcl/chat-procs.tcl 6 Feb 2006 11:45:09 -0000 1.2 @@ -8,27 +8,23 @@ namespace eval ::xowiki { Class Message -parameter {time user_id msg} Class Chat -superclass ::xo::OrderedComposite \ - -parameter {chat_id keep_nr_messages {encoder urlencode} {timewindow 600}} - Chat instproc context {user_id} { - if {![my exists now]} {my set now [clock clicks -milliseconds]} - if {$user_id == -1} {set user_id [ad_conn user_id]} - my set uid $user_id - my set array [self class]-[my set chat_id] - } + -parameter {chat_id user_id session_id {encoder urlencode} {timewindow 600}} Chat instproc init {} { - my instvar array uid now - my context 0 - if {![nsv_exists $array-seen newest]} { - nsv_set $array-seen newest $now - } + my instvar array + my set now [clock clicks -milliseconds] + if {![my exists user_id]} {my set user_id [ad_conn user_id]} + if {![my exists session_id]} {my set session_id [ad_conn session_id]} + set array [self class]-[my set chat_id] + if {![nsv_exists $array-seen newest]} {nsv_set $array-seen newest 0} } - Chat instproc add_msg {{-user_id -1} msg} { - my instvar array uid now - my context $user_id - set msg_id $now.$uid - nsv_set $array $msg_id [list $now [clock seconds] $uid $msg] + Chat instproc add_msg {{-get_new:boolean true} -uid msg} { + my instvar array now + set user_id [expr {[info exists uid] ? $uid : [my set user_id]}] + set msg_id $now.$user_id + nsv_set $array $msg_id [list $now [clock seconds] $user_id $msg] nsv_set $array-seen newest $now - my get_new -user_id $uid + nsv_set $array-last-activity $user_id $now + if {$get_new} {my get_new} } Chat instproc check_age {key ago} { my instvar array timewindow @@ -39,12 +35,11 @@ } return 1 } - Chat instproc get_new {{-user_id -1}} { - my instvar array uid now - my context $user_id - set last [expr {[nsv_exists $array-seen $uid] ? [nsv_get $array-seen $uid] : 0}] + Chat instproc get_new {} { + my instvar array now session_id + set last [expr {[nsv_exists $array-seen $session_id] ? [nsv_get $array-seen $session_id] : 0}] if {[nsv_get $array-seen newest]>$last} { - my log "--s must check $uid: [nsv_get $array-seen newest] > $last" + #my log "--c must check $session_id: [nsv_get $array-seen newest] > $last" foreach {key value} [nsv_array get $array] { foreach {timestamp secs user msg} $value break if {$timestamp > $last} { @@ -53,31 +48,41 @@ my check_age $key [expr {($now - $timestamp) / 1000}] } } - nsv_set $array-seen $uid $now + nsv_set $array-seen $session_id $now + #my log "--c setting session_id $session_id: $now" + } else { + #my log "--c nothing new for $session_id" } my render } - Chat instproc get_all {{-user_id -1}} { - my instvar array uid now - my context $user_id + Chat instproc get_all {} { + my instvar array now session_id foreach {key value} [nsv_array get $array] { foreach {timestamp secs user msg} $value break if {[my check_age $key [expr {($now - $timestamp) / 1000}]]} { my add [Message new -time $secs -user_id $user -msg $msg] } } - nsv_set $array-seen $uid $now + #my log "--c setting session_id $session_id: $now" + nsv_set $array-seen $session_id $now my render } - Chat instproc login {{-user_id -1}} { - my instvar array uid now - my context $user_id + Chat instproc login {} { + my instvar array user_id now # was the user already active? - if {![nsv_exists $array-seen $uid]} { - my add_msg -user_id $uid login + if {![nsv_exists $array-last-activity $user_id]} { + my add_msg -get_new false login } + foreach {user timestamp} [nsv_array get $array-last-activity] {;# sweeper + set ago [expr {($now - $timestamp) / 1000}] + if {$ago > 1200} { + my add_msg -get_new false -uid $user "auto logout" + nsv_unset $array-last-activity $user + } + } my encoder noencode - my get_all -user_id $uid + #my log "--c setting session_id [my set session_id]: $now" + my get_all } Chat instproc urlencode {string} {ns_urlencode $string} Chat instproc noencode {string} {set string} @@ -104,9 +109,43 @@ } return $result } + Chat proc login {-chat_id -package_id} { + 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 packages/xowiki/www/ajax/chat.js + if { ![file exists [acs_root_dir]/$path] } { + 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 get_update "chatSendCmd(\"$path/ajax/chat?m=get_new&$context\",chatReceiver)" + set get_all "chatSendCmd(\"$path/ajax/chat?m=get_all&$context\",chatReceiver)" + return "\ + +
+ " + #0 + # [ad_conn session_id] - [ns_conn url] ?? [util_current_location] + + } + if {0} { - Chat c1 -chat_id 222 + Chat c1 -chat_id 222 -session_id 123 -user_id 456 set _ "" c1 add_msg "Hello World now" append _ [c1 get_new] Index: openacs-4/packages/xowiki/www/view.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/Attic/view.adp,v diff -u -r1.6 -r1.7 --- openacs-4/packages/xowiki/www/view.adp 3 Feb 2006 22:17:41 -0000 1.6 +++ openacs-4/packages/xowiki/www/view.adp 6 Feb 2006 11:45:10 -0000 1.7 @@ -15,7 +15,7 @@ if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { - //http_request.overrideMimeType('text/xml'); + http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { @@ -33,6 +33,18 @@ return http_request; } +if (typeof DOMParser == "undefined") { + DOMParser = function () {} + + DOMParser.prototype.parseFromString = function (str, contentType) { + if (typeof ActiveXObject != "undefined") { + var d = new ActiveXObject("MSXML.DomDocument"); + d.loadXML(str); + return d; + } + } +} + var http = getHttpObject(); Index: openacs-4/packages/xowiki/www/admin/samples/ajax-chat.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/admin/samples/ajax-chat.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/xowiki/www/admin/samples/ajax-chat.tcl 3 Feb 2006 22:17:41 -0000 1.1 +++ openacs-4/packages/xowiki/www/admin/samples/ajax-chat.tcl 6 Feb 2006 11:45:10 -0000 1.2 @@ -4,40 +4,14 @@ -set lang en \ -set description {} \ -set text { -proc content {} { - auth::require_login - set chat_id 22 - set path packages/xowiki/www/ajax/chat.js - if { ![file exists [acs_root_dir]/$path] } { - 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 login_url /xowiki/ajax/chat?m=login&id=$chat_id - set send_url /xowiki/ajax/chat?m=add_msg&id=$chat_id&msg= - set get_update "chatSendCmd(\"/xowiki/ajax/chat?m=get_new&id=$chat_id\",chatReceiver)" - set get_all "chatSendCmd(\"/xowiki/ajax/chat?m=get_all&id=$chat_id\",chatReceiver)" - return " - -