Index: openacs-4/packages/chat/tcl/chat-ajax-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/tcl/chat-ajax-procs.tcl,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/chat/tcl/chat-ajax-procs.tcl 22 Jun 2007 09:05:04 -0000 1.7
+++ openacs-4/packages/chat/tcl/chat-ajax-procs.tcl 19 Nov 2007 01:14:16 -0000 1.8
@@ -9,75 +9,29 @@
namespace eval ::chat {
::xo::ChatClass Chat -superclass ::xo::Chat
-
-
- Chat instproc login {} {
- my instvar array user_id now chat_id
-
-
- db_1row room_info {
- select maximal_participants as maximal
- from chat_rooms as cp
- where cp.room_id = :chat_id
- }
- db_1row room_info {
- select count(cr.room_id) as count
- from chat_room_user_id as cr
- where cr.room_id = :chat_id
- }
- if { $count < $maximal} {
- db_1row room_info {
- select count(cr.room_id) as count2
- from chat_room_user_id as cr
- where cr.user_id = :user_id
- and cr.room_id = :chat_id
- }
- if { $count2 == 0 } {
- db_dml insert_users {insert into chat_room_user_id (room_id,user_id) values (:chat_id,:user_id);}
- }
- }
- if { $count == $maximal} {
-
- db_1row room_info {
- select count(chat_room_user_id.user_id) as count
- from chat_room_user_id
- where chat_room_user_id.user_id = :user_id
- and chat_room_user_id.room_id = :chat_id
- }
- if { $count == 0 } {
- if { [permission::permission_p -party_id $user_id -object_id [dotlrn::get_package_id] -privilege admin] } {
-
- } else {
-
- ns_return 200 text/html "
\
- [_ chat.You_dont_have_permission_room]
\
- "
- ad_script_abort
- }
- }
- }
-
- if {![nsv_exists $array-last-activity $user_id]} {
- my add_msg -get_new false [_ xotcl-core.has_entered_the_room]
-
-
- }
- my encoder noencode
- my get_all
+ Chat instproc render {} {
+ my orderby time
+ set result ""
+ 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" \
+ "$userlink:" \
+ "[my encode $msg]
\n"
+ }
+ return $result
}
-
-
-
-
- Chat proc login {-chat_id -package_id -folder_id} {
+
+ 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 jspath packages/chat/www/ajax/chat.js
if { ![file exists [acs_root_dir]/$jspath] } {
@@ -86,638 +40,28 @@
set file [open [acs_root_dir]/$jspath]; set js [read $file]; close $file
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=
- #$send_file
-
- set user_id [ad_conn user_id]
- set return_url [ad_return_url]
- db_1row room_info {
- select room.comm_name
- from chat_rooms as room
- where room.room_id = :chat_id
- }
- set folder_id "$comm_name's Public Files"
- db_1row room_info {
- select count(acs.object_id) as count
- from acs_objects as acs
- where acs.title = :folder_id
- }
- if { $count > 0 } {
- db_1row room_info {
- select acs.object_id as id
- from acs_objects as acs
- where acs.title = :folder_id
- }
- set folder_id $id
- } else {
- acs_user::get -user_id $user_id -array user
- set name [expr {$user(screen_name) ne "" ? $user(screen_name) : $user(name)}]
- set folder_id "$name's Shared Files"
-
- #$folder_id
- db_1row room_info {
- select fs.folder_id as id
- from fs_folders as fs
- where fs.name = :folder_id
- }
- set folder_id $id
- }
-
-
- set users_url ${path}ajax/chat?m=get_users&$context
-
- set files_url ${path}ajax/chat?m=get_files&$context
-
-
+ set send_url ${path}ajax/chat?m=add_msg&$context&msg=
+ set users_url ${path}ajax/chat?m=get_users&$context
return "\
-
+ "
}
-
- #test send files
-
- db_1row room_info1 {
- select count(files.message) as message
- from chat_rooms_files_sent as files
- where files.room_id = :chat_id
- and files.message = false
- }
-
- if { $message > 0 } {
- db_1row room_info1 {
- select files.title as title,files.file as fil
- from chat_rooms_files_sent as files
- where files.room_id = :chat_id
- and files.message = false
- }
-
-
-
-
-
-
- db_1row room_info {
- select room.comm_name
- from chat_rooms as room
- where room.room_id = :chat_id
- }
- set folder_id "$comm_name's Public Files"
-
- db_1row room_info {
- select count(acs.object_id) as count
- from acs_objects as acs
- where acs.title = :folder_id
- }
- if { $count > 0 } {
- db_1row room_info {
- select acs.object_id as id
- from acs_objects as acs
- where acs.title = :folder_id
- }
- set url [ad_conn url]
- set folder_id $id
- set inicio 0
- set final [expr [string length $url]-16]
- set comm_name [string range $url $inicio $final]
- if { [string length $comm_name] > 0 } {
- set url "$comm_name/file-storage/index?folder_id=$folder_id"
- }
- } else {
-
- acs_user::get -user_id $user_id -array user
- set name [expr {$user(screen_name) ne "" ? $user(screen_name) : $user(name)}]
- set folder_id "$name's Shared Files"
- #$folder_id
-
-
- db_1row room_info {
- select fs.folder_id as id
- from fs_folders as fs
- where fs.name = :folder_id
- }
- set folder_id $id
- set url "/dotlrn/file-storage/index?folder_id=$folder_id"
- }
-
-
-
- set user_file -1
-
-
- set userlink [my user_link -user_id "-1" -color ""]
- set msg_file [my user_link4 -url "I has uploaded the '$title' file ($fil) to the " -color ""]
- append result2 ""
-
- append msg_file [my user_link5 -url "$url" -msg "public files of the community" -color ""]
-
- append result2 $msg_file
- append result2 " "
- append result2 "\n"
- set delete_message [send_file_message $chat_id]
- set uid -1
- set m [my add_msg -get_new true -uid $user_id "$result2"]
-
- set userlink [my user_link -user_id $user_file -color ""]
- append result "$timeshort$userlink:"
- append result ""
- set msg_file [my user_link4 -url "The file '$title' has been sent to the " -color ""]
- append msg_file [my user_link5 -url "$url" -msg "public files of the community." -color ""]
- append result $msg_file
- append result " "
- append result "
\n"
-
-
- }
-
- return $result
- }
-
-
- Chat instproc get_files {} {
- my instvar chat_id
- set output ""
- set count 0
- ns_log Notice "en el get files... $output"
-
-
- db_foreach file "select distinct fil.file as file
- from chat_rooms_files_sent as fil
- where fil.room_id = :chat_id " {
-
-
- set url [ad_conn url]
-
- set inicio 0
- set final [expr [string length $url]-16]
- set comm_name [string range $url $inicio $final]
-
- if { [string length $comm_name] > 0 } {
- append output "$file |
"
- } else {
- set user_id [ad_conn user_id]
- acs_user::get -user_id $user_id -array user
- set name [expr {$user(screen_name) ne "" ? $user(screen_name) : $user(name)}]
- set folder_id "$name's Shared Files"
-
- db_1row room_info {
- select fs.folder_id as id
- from fs_folders as fs
- where fs.name = :folder_id
- }
- set folder_id $id
- append url_file "dotlrn_fs_" $user_id
- append url_file "_root_folder"
- append url_file2 "dotlrn_fs_" $user_id
- append url_file2 "_shared_folder"
-
- append output "$file |
"
-
- }
- } if_no_rows {
- append output "[_ chat.no_files] |
"
- }
-
- return $output
- }
-
-
-
-
- Chat instproc sweeper {} {
- my instvar array now chat_id
- my log "-- starting"
-
-
- foreach {user timestamp} [nsv_array get $array-last-activity] {
- ns_log Notice "YY at user $user with $timestamp"
- set ago [expr {($now - $timestamp) / 1000}]
-
-
- if {$ago > 1000} {
- my add_msg -get_new false -uid $user "auto logout"
- db_dml insert_users {delete from chat_room_user_id where room_id = :chat_id and user_id = :user;}
- nsv_unset $array-last-activity $user
- nsv_unset $array-color $user
- nsv_unset $array-login $user
-
- }
-
- }
- my log "-- ending"
- }
-
-
- Chat instproc get_users {} {
- my instvar chat_id
- set output ""
- set count 0
-
-
-
- foreach {user_id timestamp} [my active_user_list] {
-
-
- set count [expr $count+1]
- if {$user_id > 0} {
- db_1row room_info {
- select count(1) as info
- from chat_registered_users
- where room_id = :chat_id
- and user_id = :user_id
- }
- if { $info > 0 } {
- db_1row room_info {
- select alias as alias
- from chat_registered_users
- where room_id = :chat_id
- and user_id = :user_id
- }
-
- set pp [my sweeper]
-
-
-
- set color [my user_color $user_id]
- set diff [clock format [expr {[clock seconds] - $timestamp}] -format "%H:%M:%S" -gmt 1]
-
- set package_id [ad_conn package_id]
- db_1row url {
- select site_node__url(node_id) as url
- from site_nodes
- where object_id=:package_id
- }
-
- set userlink [my user_link2 -user_id $user_id -alias $alias]
- set user_id2 [ad_conn user_id]
- set url2 "private-room?room_id=$chat_id&user_id1=$user_id&user_id2=$user_id2"
- append link $url $url2
- set address [my encode $link]
- set narrow [dt_right_arrow]
- ns_log Notice "URL---------------$link---------$userlink"
- append output " | $userlink | $diff |
"
-
- }
- if { $info eq 0 } {
- set link ""
- set package_id [ad_conn package_id]
- db_1row url {
- select site_node__url(node_id) as url
- from site_nodes
- where object_id=:package_id
- }
- set diff [clock format [expr {[clock seconds] - $timestamp}] -format "%H:%M:%S" -gmt 1]
- set userlink [my user_link -user_id $user_id]
- set user_id2 [ad_conn user_id]
- set url2 "private-room?room_id=$chat_id&user_id1=$user_id&user_id2=$user_id2"
- append link $url $url2
- set address [my encode $link]
- set narrow [dt_right_arrow]
- ns_log Notice "URL---------------$link---------$userlink"
- append output " | $userlink | $diff |
"
- }
- }
- }
-
- return $output
- }
+}
-
-
-Chat instproc logout {} {
- my instvar array user_id chat_id
- my add_msg -get_new false [_ chat.has_left_the_room].
-
- db_dml insert_users {delete from chat_room_user_id where room_id = :chat_id and user_id = :user_id;}
-
- catch {
- nsv_unset $array-last-activity $user_id
- nsv_unset $array-login $user_id
- nsv_unset $array-color $user_id
- }
- }
-
-
-
- Chat instproc user_link { -user_id -color } {
- my instvar chat_id
- if {$user_id > 0} {
- set name [my user_name $user_id]
- set url "/shared/community-member?user%5fid=$user_id"
- if {![info exists color]} {
- set color [my user_color $user_id]
- }
- set user_id2 [ad_conn user_id]
- set user_info "#chat.user_info#"
- set creator "$name"
- } elseif { $user_id == 0 } {
- set creator "Nobody"
- } else {
- set creator "System"
- }
- return [my encode $creator]
- }
-
-
-
- Chat instproc user_link2 { -user_id -color -alias} {
- my instvar chat_id
- if {$user_id > 0} {
- set name $alias
- set url "/shared/community-member?user%5fid=$user_id"
- set user_id2 [ad_conn user_id]
- if {![info exists color]} {
- set color [my user_color $user_id]
- }
- set user_info "#chat.user_info#"
- set creator "$alias"
- ns_log Notice "El creator vale---------------$creator"
- } elseif { $user_id == 0 } {
- set creator "Nobody"
- } else {
- set creator "System"
- }
- set tt [my encode $creator]
- ns_log Notice "El creator a string vale $tt"
- return [my encode $creator]
- }
-
- Chat instproc user_link3 { -url -color} {
- set creator "$url"
-
- return [my encode $creator]
- }
-
- Chat instproc user_link4 { -url -color} {
- set creator "$url"
-
- return [my encode $creator]
- }
-
- Chat instproc user_link5 { -url -msg -color} {
- set creator "$msg"
-
- return [my encode $creator]
- }
-
-
- Chat instproc add_msg {{-get_new:boolean true} -uid msg} {
- my instvar array now user_id chat_id
-
- if { $get_new eq "true" } {
-
- db_1row room_info {
- select count(cr.room_id) as count
- from chat_room_user_id as cr
- where cr.room_id = :chat_id
- and cr.user_id = :user_id
- }
- if { $count == 1 || [permission::permission_p -party_id $user_id -object_id [dotlrn::get_package_id] -privilege admin]} {
- set user_id [expr {[info exists uid] ? $uid : [my set user_id]}]
- set color [my user_color $user_id]
- set msg $msg
-
- if {$get_new && [info command ::thread::mutex] ne ""} {
-
- my broadcast_msg [Message new -volatile -time [clock seconds] \
- -user_id $user_id -msg $msg -color $color]
-
- }
-
- set msg_id $now.$user_id
- if { ![nsv_exists $array-login $user_id] } {
- nsv_set $array-login $user_id [clock seconds]
- }
-
- nsv_set $array $msg_id [list $now [clock seconds] $user_id $msg $color]
- nsv_set $array-seen newest $now
- nsv_set $array-seen last [clock seconds]
- nsv_set $array-last-activity $user_id $now
- if {$get_new} {my get_new}
- }
-
-
- } else {
-
- set user_id [expr {[info exists uid] ? $uid : [my set user_id]}]
- set color [my user_color $user_id]
-
- set msg $msg
-
-
- if {$get_new && [info command ::thread::mutex] ne ""} {
-
- my broadcast_msg [Message new -volatile -time [clock seconds] \
- -user_id $user_id -msg $msg -color $color]
-
- }
-
- set msg_id $now.$user_id
- if { ![nsv_exists $array-login $user_id] } {
- nsv_set $array-login $user_id [clock seconds]
- }
- nsv_set $array $msg_id [list $now [clock seconds] $user_id $msg $color]
- nsv_set $array-seen newest $now
- nsv_set $array-seen last [clock seconds]
- nsv_set $array-last-activity $user_id $now
- if {$get_new} {my get_new}
- }
-
- }
-
-
-}