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 -N -r1.3 -r1.4 --- openacs-4/packages/xowiki/tcl/chat-procs.tcl 25 Feb 2006 13:36:23 -0000 1.3 +++ openacs-4/packages/xowiki/tcl/chat-procs.tcl 31 Mar 2006 19:36:45 -0000 1.4 @@ -6,87 +6,8 @@ @cvs-id $Id$ } namespace eval ::xowiki { - Class Message -parameter {time user_id msg} - Class Chat -superclass ::xo::OrderedComposite \ - -parameter {chat_id user_id session_id {encoder urlencode} {timewindow 600}} - Chat instproc init {} { - 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 {{-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 - nsv_set $array-last-activity $user_id $now - if {$get_new} {my get_new} - } - Chat instproc check_age {key ago} { - my instvar array timewindow - if {$ago > $timewindow} { - nsv_unset $array $key - #my log "--c unsetting $key" - return 0 - } - return 1 - } - 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 "--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} { - my add [Message new -time $secs -user_id $user -msg $msg] - } else { - my check_age $key [expr {($now - $timestamp) / 1000}] - } - } - 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 {} { - 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] - } - } - #my log "--c setting session_id $session_id: $now" - nsv_set $array-seen $session_id $now - my render - } - Chat instproc login {} { - my instvar array user_id now - # was the user already active? - 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 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} - Chat instproc encode {string} {my [my encoder] $string} + ::xo::ChatClass Chat -superclass ::xo::Chat + Chat instproc render {} { my orderby time set result "" @@ -109,6 +30,9 @@ } return $result } + + Chat proc initialize_nsvs {} {;} ;# noop + Chat proc login {-chat_id -package_id} { auth::require_login ::xowiki::Page requireJS "/resources/xowiki/get-http-object.js" @@ -140,9 +64,6 @@ " - #0 - #  [ad_conn session_id] - [ns_conn url] ?? [util_current_location] - } if {0} { @@ -153,4 +74,4 @@ ns_return 200 text/html $_ } -} \ No newline at end of file +}