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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/tcl/chat-procs.tcl 3 Feb 2006 22:17:41 -0000 1.1 @@ -0,0 +1,116 @@ +ad_library { + XoWiki - chat procs + + @creation-date 2006-02-02 + @author Gustaf Neumann + @cvs-id $Id: chat-procs.tcl,v 1.1 2006/02/03 22:17:41 gustafn Exp $ +} +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] + } + Chat instproc init {} { + my instvar array uid now + my context 0 + if {![nsv_exists $array-seen newest]} { + nsv_set $array-seen newest $now + } + } + 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] + nsv_set $array-seen newest $now + my get_new -user_id $uid + } + 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 {{-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}] + if {[nsv_get $array-seen newest]>$last} { + my log "--s must check $uid: [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 $uid $now + } + my render + } + Chat instproc get_all {{-user_id -1}} { + my instvar array uid now + my context $user_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 render + } + Chat instproc login {{-user_id -1}} { + my instvar array uid now + my context $user_id + # was the user already active? + if {![nsv_exists $array-seen $uid]} { + my add_msg -user_id $uid login + } + my encoder noencode + my get_all -user_id $uid + } + Chat instproc urlencode {string} {ns_urlencode $string} + Chat instproc noencode {string} {set string} + Chat instproc encode {string} {my [my encoder] $string} + 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 "
" + set added 0 + set replaced 0 + foreach o $objects { + $o set parent_id $folder_id + $o set package_id $package_id + $o set creation_user $user_id + # page instances have references to page templates, add these first + if {[$o istype ::xowiki::PageInstance]} continue + set item [CrItem lookup -title [$o set title] -parent_id $folder_id] + if {$item != 0 && $replace} { ;# we delete the original + ::Generic::CrItem delete -item_id $item + set item 0 + incr replaced + } + if {$item == 0} { + $o save_new + incr added + } + } + + foreach o $objects { + if {[$o istype ::xowiki::PageInstance]} { + db_transaction { + set item [CrItem lookup -title [$o set title] -parent_id $folder_id] + if {$item != 0 && $replace} { ;# we delete the original + ::Generic::CrItem delete -item_id $item + set item 0 + incr replaced + } + if {$item == 0} { ;# the item does not exist -> update reference and save + set old_template_id [$o set page_template] + set template [CrItem lookup \ + -title [$old_template_id set title] \ + -parent_id $folder_id] + $o set page_template $template + $o save_new + incr added + } + } + } + $o destroy + } + append msg "$added objects inserted, $replaced objects replaced
" + } + # # data definitions # 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.5 -r1.6 --- openacs-4/packages/xowiki/www/view.adp 30 Jan 2006 02:04:51 -0000 1.5 +++ openacs-4/packages/xowiki/www/view.adp 3 Feb 2006 22:17:41 -0000 1.6 @@ -5,9 +5,37 @@ + +
" - set added 0 - foreach o [$object_type allinstances] { - $o set parent_id $folder_id - $o set package_id [ad_conn package_id] - # page instances have references to page templates, add these first - if {[$o istype ::xowiki::PageInstance]} continue - set item [CrItem lookup -title [$o set title] -parent_id $folder_id] - if {$item != 0 && $replace} { ;# we delete the original - ::Generic::CrItem delete -item_id $item - set item 0 - } - if {$item == 0} { - $o save_new - incr added - } - } - - foreach o [$object_type allinstances] { - if {[$o istype ::xowiki::PageInstance]} { - db_transaction { - set item [CrItem lookup -title [$o set title] -parent_id $folder_id] - if {$item != 0 && $replace} { ;# we delete the original - ::Generic::CrItem delete -item_id $item - set item 0 - } - if {$item == 0} { ;# the item does not exist -> update reference and save - set old_template_id [$o set page_template] - set template [CrItem lookup \ - -title [$old_template_id set title] \ - -parent_id $folder_id] - $o set page_template $template - $o save_new - incr added - } - } - } - $o destroy - } - append msg "$added objects inserted
" + set msg [::xowiki::Page import] } } 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 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/xowiki/www/admin/samples/ajax-chat.tcl 3 Feb 2006 22:17:41 -0000 1.1 @@ -0,0 +1,46 @@ +namespace eval ::xowiki::tmp { + ::xowiki::Object create ajax-chat -noinit \ + -set object_type ::xowiki::Object \ + -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 " + +