Index: openacs-4/packages/chat/catalog/chat.en_US.ISO-8859-1.xml =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/catalog/chat.en_US.ISO-8859-1.xml,v diff -u -N -r1.7.4.1 -r1.7.4.2 --- openacs-4/packages/chat/catalog/chat.en_US.ISO-8859-1.xml 8 Nov 2016 17:28:23 -0000 1.7.4.1 +++ openacs-4/packages/chat/catalog/chat.en_US.ISO-8859-1.xml 22 Nov 2016 18:34:35 -0000 1.7.4.2 @@ -104,6 +104,7 @@ Room name Room no active Room not found, Invalid room id + rooms Send/Refresh Sending message... There are no rooms available Index: openacs-4/packages/chat/sql/postgresql/chat-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/sql/postgresql/chat-create.sql,v diff -u -N -r1.8.2.3 -r1.8.2.4 --- openacs-4/packages/chat/sql/postgresql/chat-create.sql 28 Oct 2016 19:10:17 -0000 1.8.2.3 +++ openacs-4/packages/chat/sql/postgresql/chat-create.sql 22 Nov 2016 18:34:35 -0000 1.8.2.4 @@ -203,7 +203,7 @@ default 't' constraint chat_rooms_archive_p_ck check (archive_p in ('t', 'f')), - -- flush the rooms messages every night at 00:05 + -- flush the rooms messages every night at 00:05 auto_flush_p boolean default 't', -- automatically create a transcript after flushing the room auto_transcript_p boolean default 'f', @@ -362,7 +362,7 @@ p_auto_flush_p boolean, p_auto_transcript_p boolean, p_login_messages_p boolean, - p_logout_messages_p boolean, + p_logout_messages_p boolean, p_context_id integer, p_creation_date timestamptz, p_creation_user integer, @@ -611,7 +611,7 @@ p_auto_flush_p boolean, p_auto_transcript_p boolean, p_login_messages_p boolean, - p_logout_messages_p boolean + p_logout_messages_p boolean ) RETURNS integer AS $$ DECLARE BEGIN @@ -625,10 +625,10 @@ auto_flush_p = p_auto_flush_p, auto_transcript_p = p_auto_transcript_p, login_messages_p = p_login_messages_p, - logout_messages_p = p_logout_messages_p + logout_messages_p = p_logout_messages_p where room_id = p_room_id; - + return 0; END; $$ LANGUAGE plpgsql; @@ -639,16 +639,16 @@ -- added -select define_function_args('chat_room__message_post','room_id,msg,html_p,approved_p'); +select define_function_args('chat_room__message_post','room_id,msg,creation_user,creation_ip'); -- -- procedure chat_room__message_post/4 -- CREATE OR REPLACE FUNCTION chat_room__message_post( p_room_id integer, p_msg varchar, - p_html_p integer, - p_approved_p varchar + p_creation_user integer, + p_creation_ip varchar ) RETURNS integer AS $$ DECLARE v_msg_id chat_msgs.msg_id%TYPE; @@ -658,7 +658,6 @@ -- Get msg id from the global acs_object sequence. select nextval('t_acs_object_id_seq') into v_msg_id from dual; - select archive_p into v_msg_archive_p from chat_rooms where room_id = p_room_id; if v_msg_archive_p = 't' then @@ -667,9 +666,8 @@ v_msg := null; end if; - -- TO DO: aproved_p, Hhtml_p and lengh - -- Insert into chat_msgs table. - insert into chat_msgs ( + -- Insert into chat_msgs table. + insert into chat_msgs ( msg_id, room_id, msg, @@ -720,100 +718,3 @@ return 0; END; $$ LANGUAGE plpgsql; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: openacs-4/packages/chat/sql/postgresql/upgrade/upgrade-5.0d11-5.0d12.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/sql/postgresql/upgrade/upgrade-5.0d11-5.0d12.sql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/chat/sql/postgresql/upgrade/upgrade-5.0d11-5.0d12.sql 22 Nov 2016 18:34:35 -0000 1.1.2.1 @@ -0,0 +1,57 @@ +begin; + +-- correct bad parameter naming in this function + +DROP FUNCTION chat_room__message_post(integer,character varying,integer,character varying); + +-- added +select define_function_args('chat_room__message_post','room_id,msg,creation_user,creation_ip'); + +-- +-- procedure chat_room__message_post/4 +-- +CREATE OR REPLACE FUNCTION chat_room__message_post( + p_room_id integer, + p_msg varchar, + p_creation_user integer, + p_creation_ip varchar +) RETURNS integer AS $$ +DECLARE + v_msg_id chat_msgs.msg_id%TYPE; + v_msg_archive_p chat_rooms.archive_p%TYPE; + v_msg chat_msgs.msg%TYPE; +BEGIN + -- Get msg id from the global acs_object sequence. + select nextval('t_acs_object_id_seq') into v_msg_id from dual; + + select archive_p into v_msg_archive_p from chat_rooms where room_id = p_room_id; + + if v_msg_archive_p = 't' then + v_msg := p_msg; + else + v_msg := null; + end if; + + -- Insert into chat_msgs table. + insert into chat_msgs ( + msg_id, + room_id, + msg, + creation_user, + creation_ip, + creation_date) + values ( + v_msg_id, + p_room_id, + v_msg, + p_creation_user, + p_creation_ip, + now()) ; + + + +return 0; +END; +$$ LANGUAGE plpgsql; + +end; 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 -N -r1.12.2.2 -r1.12.2.3 --- openacs-4/packages/chat/tcl/chat-ajax-procs.tcl 28 Oct 2016 18:57:36 -0000 1.12.2.2 +++ openacs-4/packages/chat/tcl/chat-ajax-procs.tcl 22 Nov 2016 18:34:35 -0000 1.12.2.3 @@ -4,19 +4,19 @@ @creation-date 2006-02-02 @author Gustaf Neumann @author Peter Alberer - @cvs-id $Id$ + @cvs-id $Id$ } namespace eval ::chat { ::xo::ChatClass Chat -superclass ::xo::Chat Chat instproc init {} { - my instvar chat_id login_messages_p logout_messages_p - xo::dc 1row get_options " - select login_messages_p, - logout_messages_p - from chat_rooms - where room_id = :chat_id" + :instvar chat_id + if {[chat_room_exists_p $chat_id]} { + chat_room_get -room_id $chat_id -array c + :set login_messages_p $c(login_messages_p) + :set logout_messages_p $c(logout_messages_p) + } next } @@ -30,20 +30,23 @@ 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" + append result " +

+ $timeshort + $userlink: + [my encode $msg] +

\n" } return $result } Chat proc login {-chat_id -package_id} { - auth::require_login + auth::require_login if {![info exists package_id]} { - set package_id [ad_conn package_id] + set package_id [ad_conn package_id] } if {![info exists chat_id]} { - set chat_id $package_id + set chat_id $package_id } set context "id=$chat_id&s=[ad_conn session_id].[clock seconds]" @@ -60,20 +63,20 @@ set users_url [ns_quotehtml "${path}ajax/chat?m=get_users&$context"] set html_url [ns_quotehtml [ad_conn url]?[ad_conn query]] regsub {client=ajax} $html_url {client=html} html_url - + return "\ -
- - @@ -85,9 +88,9 @@ #chat.message# -
+ - " } -} + # if chat doesn't exist anymore, send a message that will inform + # the user of being looking at an invalid chat + Chat instproc check_valid_room {} { + if {![chat_room_exists_p [:chat_id]]} { + ns_return 500 text/plain [_ chat.Room_not_found] + ad_script_abort + } + } + + Chat instproc get_new {} { + :check_valid_room + next + } + + Chat instproc add_msg { + {-get_new:boolean true} + {-uid ""} + msg + } { + :check_valid_room + + # ignore empty messages + if {$msg eq ""} return + + # code around expects the return value of the original method + set retval [next] + + # This way messages can be persisted immediately everytime a + # message is sent + if {[:current_message_valid]} { + chat_message_post [:chat_id] [:user_id] $msg 1 + } + + return $retval + } +} Index: openacs-4/packages/chat/tcl/chat-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/tcl/chat-procs-postgresql.xql,v diff -u -N -r1.6.6.2 -r1.6.6.3 --- openacs-4/packages/chat/tcl/chat-procs-postgresql.xql 28 Oct 2016 18:57:36 -0000 1.6.6.2 +++ openacs-4/packages/chat/tcl/chat-procs-postgresql.xql 22 Nov 2016 18:34:35 -0000 1.6.6.3 @@ -1,222 +1,104 @@ - postgresql7.1 - - - select chat_room__new ( - NULL, - :pretty_name, - :description, - :moderated_p, - :active_p, - :archive_p, - :auto_flush_p, - :auto_transcript_p, - :login_messages_p, - :logout_messages_p, - :context_id, - now(), - :creation_user, - :creation_ip, - 'chat_room' - ) - - + postgresql7.1 + + + select chat_room__new ( + NULL, + :pretty_name, + :description, + :moderated_p, + :active_p, + :archive_p, + :auto_flush_p, + :auto_transcript_p, + :login_messages_p, + :logout_messages_p, + :context_id, + now(), + :creation_user, + :creation_ip, + 'chat_room' + ) + + + + + select chat_room__edit ( + :room_id, + :pretty_name, + :description, + :moderated_p, + :active_p, + :archive_p, + :auto_flush_p, + :auto_transcript_p, + :login_messages_p, + :logout_messages_p + ) + + - - - -- Automatic grant room privilege to creator of the room (must not be null). - begin - if :creation_user <> '' - then - perform acs_permission__grant_permission(:room_id, :creation_user, 'chat_room_edit'); - perform acs_permission__grant_permission(:room_id, :creation_user, 'chat_room_view'); - perform acs_permission__grant_permission(:room_id, :creation_user, 'chat_room_delete'); - perform acs_permission__grant_permission(:room_id, :creation_user, 'chat_transcript_create'); + + + select chat_room__message_count(:room_id) + + - end if; - return 0; - end; + + + select chat_room__delete_all_msgs(:room_id) + + - - - - - select chat_room__name (:room_id) from dual; - - + + + select chat_transcript__new ( + :pretty_name, + :contents, + :description, + :room_id, + :context_id, + now(), + :creation_user, + :creation_ip, + 'chat_transcript' + ) + + + + + select chat_transcript__del(:transcript_id) + + - - - begin - perform acs_permission__grant_permission(:room_id, :party_id, 'chat_write'); - perform acs_permission__grant_permission(:room_id, :party_id, 'chat_read'); - return 0; - end; - - + + + select chat_room__message_post(:room_id, :msg, :creation_user, :creation_ip) + + + + + select chat_room__del(:room_id) + + - - - begin - perform acs_permission__revoke_permission(:room_id, :party_id, 'chat_write'); - perform acs_permission__revoke_permission(:room_id, :party_id, 'chat_read'); - return 0; - end; - - + + + select chat_transcript__edit ( + :transcript_id, + :pretty_name, + :contents, + :description + ) + + - - - begin - perform acs_permission__grant_permission(:room_id, :party_id, 'chat_ban'); - return 0; - end; - - - - - - - begin - perform acs_permission__revoke_permission(:room_id, :party_id, 'chat_ban'); - return 0; - end; - - - - - - begin - perform acs_permission__grant_permission(:room_id, :party_id, 'chat_room_moderate'); - return 0; - end; - - - - - - begin - perform acs_permission__revoke_permission(:room_id, :party_id, 'chat_room_moderate'); - return 0; - end; - - - - - - - begin - perform chat_room__edit ( - :room_id, - :pretty_name, - :description, - :moderated_p, - :active_p, - :archive_p, - :auto_flush_p, - :auto_transcript_p, - :login_messages_p, - :logout_messages_p - ); - return 0; - end; - - - - - - - select chat_room__message_count(:room_id); - - - - - - - begin - perform chat_room__delete_all_msgs(:room_id); - return 0; - end; - - - - - - - select chat_transcript__new ( - :pretty_name, - :contents, - :description, - :room_id, - :context_id, - now(), - :creation_user, - :creation_ip, - 'chat_transcript' - ) - - - - - - - begin - -- Automatic grant transcript privilege to creator of the transcript (must not be null). - if :creation_user is not null - then - perform acs_permission__grant_permission(:transcript_id, :creation_user, 'chat_transcript_edit'); - perform acs_permission__grant_permission(:transcript_id, :creation_user, 'chat_transcript_view'); - perform acs_permission__grant_permission(:transcript_id, :creation_user, 'chat_transcript_delete'); - end if; - return 0; - end; - - - - - - - begin - perform chat_transcript__del(:transcript_id); - return 0; - end; - - - - - - - select chat_room__message_post (:room_id, :msg, :creation_user, :creation_ip); - - - - - - select chat_room__del(:room_id); - - - - - - - - begin - perform chat_transcript__edit ( - :transcript_id, - :pretty_name, - :contents, - :description); - return 0; - end; - - - Index: openacs-4/packages/chat/tcl/chat-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/tcl/chat-procs.tcl,v diff -u -N -r1.11.6.2 -r1.11.6.3 --- openacs-4/packages/chat/tcl/chat-procs.tcl 28 Oct 2016 18:57:36 -0000 1.11.6.2 +++ openacs-4/packages/chat/tcl/chat-procs.tcl 22 Nov 2016 18:34:35 -0000 1.11.6.3 @@ -7,7 +7,10 @@ @cvs-id $Id$ } -ad_proc -private chat_start_server {} { Start Java chat server. } { +ad_proc -private chat_start_server { +} { + Start Java chat server. +} { if {[nsv_get chat server_started]} { return @@ -43,7 +46,12 @@ nsv_set chat server_started 1 } -ad_proc -private chat_broadcast_to_applets {host port} { Broadcast chat message from HTML client to Java server. } { +ad_proc -private chat_broadcast_to_applets { + host + port +} { + Broadcast chat message from HTML client to Java server. +} { # Chat server must already started otherwise error will occur. set fds [ns_sockopen -nonblock $host $port] @@ -70,9 +78,13 @@ } } +ad_proc -private chat_receive_from_server { + host + port +} { + Receive messages from Java clients. +} { -ad_proc -private chat_receive_from_server {host port} { Receive messages from Java clients. } { - set fds [ns_sockopen -nonblock $host $port] set r [lindex $fds 0] @@ -81,7 +93,13 @@ ns_log Notice "chat_receive_from_server: Listening for messages from applets." - puts $w "-1AOL_READERT-1" + puts $w " + + -1 + AOL_READER + T + -1 + " flush $w set running 1 @@ -93,45 +111,34 @@ foreach r $rfds { if {[ns_sockcheck $r] && [set line [string trim [gets $r]]] != ""} { - + regexp "(.*)" $line match room_id regexp "(.*)" $line match screen_name regexp "(.*)" $line match msg regexp "(.*)" $line match user_id if {![nsv_exists chat_room $room_id]} { - nsv_set chat_room $room_id {} + nsv_set chat_room $room_id {} } - ns_log Notice "YY Nachricht: $msg" ::chat::Chat c1 -volatile -chat_id $room_id -user_id $user_id -session_id 0 switch $msg { "/enter" { c1 login - # apisano: I think we don't need explicit - # message about entering the room, as this is - # already issued by the login method of parent - # chat class in xotcl-core. - # set msg [_ xotcl-core.has_entered_the_room] } "/leave" { c1 logout - # apisano: I think we don't need explicit - # message about leaving the room, as this is - # already issued by the logout method of parent - # chat class in xotcl-core. - # set msg [_ xotcl-core.has_left_the_room] } default { c1 add_msg -uid $user_id $msg } } - chat_room_get -room_id $room_id -array room_info - if { $room_info(archive_p) == "t" } { - if {[catch {chat_post_message_to_db -creation_user $user_id $room_id $msg} errmsg]} { - ns_log error "chat_post_message_to_db: error: $errmsg" - } - } + chat_room_get -room_id $room_id -array room_info + if { $room_info(archive_p) == "t" } { + if {[catch {chat_post_message_to_db -creation_user $user_id $room_id $msg} errmsg]} { + ns_log error "chat_post_message_to_db: error: $errmsg" + } + } nsv_lappend chat_room $room_id $line @@ -150,11 +157,36 @@ } { Log chat message to the database. } { - # ns_log Notice $msg - db_exec_plsql post_message {} + db_string post_message {} +} +# create a cache for the chat package +if {"chat_room_get_not_cached" ni [ns_cache_names]} { + ns_cache_create chat_room_get_not_cached 1000 } +ad_proc -public chat_room_get { + {-room_id {}} + {-array:required} +} { + Get all the information about a chat room into an array +} { + upvar $array row + array set row [ns_cache_eval -- chat_room_get_not_cached $room_id { + chat_room_get_not_cached $room_id + }] +} + +ad_proc -private chat_room_get_not_cached { + room_id +} { + db_1row select_user_info { + select * from chat_rooms + where room_id = :room_id + } -column_array row + return [array get row] +} + ad_proc -public chat_room_new { {-description ""} {-moderated_p f} @@ -168,19 +200,41 @@ {-creation_user ""} {-creation_ip ""} pretty_name - } { Create new chat room. Return room_id if successful else raise error. -} { +} { db_transaction { set room_id [db_string create_room {}] + if {$creation_user ne ""} { + foreach privilege {edit view delete} { + permission::grant \ + -party_id $creation_user \ + -object_id $room_id \ + -privilege chat_room_${privilege} + } + permission::grant \ + -party_id $creation_user \ + -object_id $room_id \ + -privilege chat_transcript_create + } } - db_exec_plsql grant_permission {} - return $room_id } +ad_proc -public chat_room_exists_p { + room_id +} { + Return wether a chat room exists + + @return a boolean +} { + return [db_0or1row query { + select 1 from chat_rooms + where room_id = :room_id + }] +} + ad_proc -public chat_room_edit { room_id pretty_name @@ -195,53 +249,51 @@ } { Edit information on chat room. All information require. } { - db_exec_plsql edit_room {} + db_string edit_room {} + ns_cache_flush -- chat_room_get_not_cached $room_id } ad_proc -public chat_room_delete { room_id } { Delete chat room. } { - db_exec_plsql delete_room {} + db_string delete_room {} + ns_cache_flush -- chat_room_get_not_cached $room_id } ad_proc -public chat_room_message_delete { room_id } { Delete all message in the room. } { - db_exec_plsql delete_message {} + db_string delete_message {} } ad_proc -public chat_message_count { room_id } { Get message count in the room. } { - - return [db_exec_plsql message_count {}] + return [db_string message_count {} -default 0] } - - ad_proc -public room_active_status { room_id } { Get room active status. } { - - return [db_string get_active { select active_p from chat_rooms where room_id = :room_id}] - + chat_room_get -room_id $room_id -array c + return $c(active_p) } ad_proc -public chat_room_name { room_id } { Get chat room name. } { - return [db_string get_room_name {} -default "" ] - + chat_room_get -room_id $room_id -array c + return $c(pretty_name) } ad_proc -public chat_moderator_grant { @@ -250,7 +302,10 @@ } { Grant party a chat moderate privilege to this chat room. } { - db_exec_plsql grant_moderator {} + permission::grant \ + -party_id $party_id \ + -object_id $room_id \ + -privilege "chat_room_moderate" } ad_proc -public chat_moderator_revoke { @@ -259,9 +314,10 @@ } { Revoke party a chat moderate privilege to this chat room. } { - - db_exec_plsql revoke_moderator {} - + permission::revoke \ + -party_id $party_id \ + -object_id $room_id \ + -privilege "chat_room_moderate" } ad_proc -public chat_user_grant { @@ -271,19 +327,28 @@ Grant party a chat privilege to this chat room. } { db_transaction { - db_exec_plsql grant_user {} + foreach privilege {read write} { + permission::grant \ + -party_id $party_id \ + -object_id $room_id \ + -privilege chat_${privilege} + } } } - ad_proc -public chat_user_revoke { room_id party_id } { Revoke party a chat privilege to this chat room. } { db_transaction { - db_exec_plsql revoke_user {} + foreach privilege {read write} { + permission::revoke \ + -party_id $party_id \ + -object_id $room_id \ + -privilege chat_${privilege} + } } } @@ -293,21 +358,22 @@ } { Explicit ban user from this chat room. } { - util_memoize_flush \ - "permission::permission_p_not_cached -party_id $party_id -object_id $room_id -privilege chat_ban" - db_exec_plsql ban_user {} + permission::grant \ + -party_id $party_id \ + -object_id $room_id \ + -privilege "chat_ban" } - ad_proc -public chat_user_unban { room_id party_id } { unban user from this chat room. } { - util_memoize_flush \ - "permission::permission_p_not_cached -party_id $party_id -object_id $room_id -privilege chat_ban" - db_exec_plsql ban_user {} + permission::revoke \ + -party_id $party_id \ + -object_id $room_id \ + -privilege "chat_ban" } ad_proc -public chat_revoke_moderators { @@ -317,28 +383,20 @@ Revoke a list of parties of a moderate privilege from this room. } { foreach party_id $revoke_list { - db_dml revoke_moderate { - begin - acs_persmission.revoke_permission(:room_id, :party_id, 'chat_moderate_room'); - end - } + permission::revoke \ + -party_id $party_id \ + -object_id $room_id \ + -privilege "chat_moderate_room" } - } ad_proc -public chat_room_moderate_p { room_id } { Return the moderate status of this chat room. } { - set moderate_p [db_string get_chat_room_moderate { - select moderated_p - from chat_rooms - where room_id = :room_id - }] - - return $moderate_p - + chat_room_get -room_id $room_id -array c + return $c(moderated_p) } ad_proc -public chat_user_name { @@ -359,7 +417,7 @@ } { Post message to the chat room and broadcast to all applet clients. Used by ajax + html. } { - if {$moderator_p == 1 } { + if {$moderator_p == 1} { set status "approved" } else { set status "pending" @@ -369,23 +427,22 @@ if {$default_client eq "java"} { set chat_msg "[chat_user_name $user_id]$user_id$room_id$message$status" - # Add message to queue. Notify thread responsible for + # Add message to queue. Notify thread responsible for # broadcast message to applets. nsv_set chat html_message $chat_msg - ns_mutex unlock [nsv_get chat new_message] + ns_mutex unlock [nsv_get chat new_message] } - + # do not write messages to the database if the room should not be archived chat_room_get -room_id $room_id -array room_info if { $room_info(archive_p) == "f" } { return } - + # write message to the database if {[catch {chat_post_message_to_db -creation_user $user_id $room_id $message} errmsg]} { ns_log error "chat_post_message_to_db: error: $errmsg" } } - ad_proc -public chat_moderate_message_post { room_id user_id @@ -405,31 +462,21 @@ room_id user_id } { - Retrieve all messages from the chat room starting from first_msg_id. Return messages are store in multirow format. + Retrieve all messages from the chat room starting from + first_msg_id. Return messages are store in multirow format. } { - ns_log debug "chat_message_retrieve: starting message retrieve" # The first time html client enter chat room, chat_room variable # is not initialize correctly. Therefore I just hard code the - # variable. - # apisano: I don't think hardcoded message should be here anymore, - # as message about user entering the room is already issued by the - # parent chat class in xotcl-core when we issue the login method + # variable. if {![nsv_exists chat_room $room_id]} { nsv_set chat_room $room_id {} - # nsv_set chat_room $room_id [list " - # - # [chat_user_name $user_id] - # $room_id - # [_ chat.has_entered_the_room] - # approved - # "] } set user_name [chat_user_name $user_id] - upvar "$msgs:rowcount" counter + upvar "$msgs:rowcount" counter set chat_messages [nsv_get chat_room $room_id] @@ -438,16 +485,15 @@ set cnt $count set counter 0 - #foreach msg $chat_messages - for { set i [expr {$cnt - 1}] } { $i >= 0 } { set i [expr {$i - 1}] } { + #foreach msg $chat_messages + for { set i [expr {$cnt - 1}] } { $i >= 0 } { incr i -1 } { set msg [lindex $chat_messages $i] regexp "(.*)" $msg match screen_name regexp "(.*)" $msg match chat_msg regexp "(.*)" $msg match status - - if {$status eq "pending" || $status eq "rejected"} { - continue; + if {$status in {"pending" "rejected"}} { + continue } upvar "$msgs:[expr {$counter + 1}]" array_val @@ -461,10 +507,8 @@ return } } - } - ad_proc -public chat_transcript_new { {-description ""} {-context_id ""} @@ -476,25 +520,28 @@ } { Create chat transcript. } { - db_transaction { - set transcript_id [db_exec_plsql create_transcript {}] - if { $transcript_id ne 0 } { + set transcript_id [db_string create_transcript {}] + if { $transcript_id != 0 } { db_dml update_contents {} - db_exec_plsql grant_permission {} + foreach privilege {edit view delete} { + permission::grant \ + -party_id $creation_user \ + -object_id $transcript_id \ + -privilege chat_transcript_${privilege} + } } } return $transcript_id - } ad_proc -public chat_transcript_delete { transcript_id } { Delete chat transcript. } { - db_exec_plsql delete_transcript {} + db_string delete_transcript {} } ad_proc -public chat_transcript_edit { @@ -505,54 +552,45 @@ } { Edit chat transcript. } { - db_exec_plsql edit_transcript {} - db_dml update_contents {} + db_transaction { + db_string edit_transcript {} + db_dml update_contents {} + } } -ad_proc -public chat_room_get { - {-room_id {}} - {-array:required} +ad_proc -private chat_flush_rooms {} { + Flush the messages in all of the chat rooms } { - Get all the information about a chat room into an array -} { - upvar $array row - array set row [util_memoize [list chat_room_get_not_cached $room_id]] -} - -ad_proc -private chat_room_get_not_cached { - room_id -} { - db_1row select_user_info {select * from chat_rooms where room_id = :room_id} -column_array row - return [array get row] -} - -ad_proc -private chat_flush_rooms {} {Flush the messages in all of the chat rooms} { - # ns_log Notice "YY Starting chat_flush_rooms operation" - set room_ids [db_list get_rooms *SQL*] + set room_ids [db_list get_rooms *SQL*] foreach room_id $room_ids { chat_room_flush $room_id } -} +} -ad_proc -private chat_room_flush { room_id } {Flush the messages a single chat room} { - # ns_log Notice "YY flushing room $room_id" +ad_proc -private chat_room_flush { + room_id +} { + Flush the messages a single chat room +} { db_transaction { - array set room_info [chat_room_get_not_cached $room_id] - set contents "" + chat_room_get $room_id -array room_info # do we have to create a transcript for the room if { $room_info(auto_transcript_p) == "t" } { # build a list of all messages - db_foreach get_archives_messages {} { - append contents "\[$creation_date\] [chat_user_name $creation_user]: $msg
\n" + set contents [list] + foreach message [db_list_of_lists get_archives_messages {}] { + lassign $message msg creation_user creation_date + lappend contents "\[$creation_date\] [chat_user_name $creation_user]: $msg" } if { $contents ne "" } { + set today [clock format [clock seconds] -format "%d.%m.%Y"] chat_transcript_new \ -description "#chat.automatically_created_transcript#" \ - "#chat.transcript_of_date# [clock format [clock seconds] -format "%d.%m.%Y"]" $contents $room_id + "#chat.transcript_of_date# $today" \ + [join $contents "
\n"] $room_id } } # clear all the messages in the room chat_room_message_delete $room_id } } - Index: openacs-4/packages/chat/www/chat.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/chat.tcl,v diff -u -N -r1.13.4.1 -r1.13.4.2 --- openacs-4/packages/chat/www/chat.tcl 20 Jun 2016 08:40:23 -0000 1.13.4.1 +++ openacs-4/packages/chat/www/chat.tcl 22 Nov 2016 18:34:35 -0000 1.13.4.2 @@ -8,7 +8,7 @@ @cvs-id $Id$ } { room_id:naturalnum,notnull - {client "ajax"} + {client "ajax"} {message:html ""} } -properties { context:onevalue @@ -27,6 +27,7 @@ if { [catch {set room_name [chat_room_name $room_id]} errmsg] } { ad_return_complaint 1 "[_ chat.Room_not_found]" + ad_script_abort } set doc(title) $room_name @@ -36,9 +37,9 @@ auth::require_login set user_id [ad_conn user_id] -set read_p [permission::permission_p -object_id $room_id -privilege "chat_read"] +set read_p [permission::permission_p -object_id $room_id -privilege "chat_read"] set write_p [permission::permission_p -object_id $room_id -privilege "chat_write"] -set ban_p [permission::permission_p -object_id $room_id -privilege "chat_ban"] +set ban_p [permission::permission_p -object_id $room_id -privilege "chat_ban"] set moderate_room_p [chat_room_moderate_p $room_id] if { $moderate_room_p == "t" } { @@ -57,11 +58,6 @@ # Get chat screen name. set user_name [chat_user_name $user_id] -# send message to the database -if { $message ne "" } { - chat_message_post $room_id $user_id $message $moderator_p -} - # Determine which template to use for html or ajax client switch $client { "html" { @@ -76,16 +72,6 @@ "ajax" { set template_use "ajax-chat-script" } - "java" { - set template_use "java-chat" - - # Get config paramater for applet. - set width [parameter::get -parameter AppletWidth -default 500] - set height [parameter::get -parameter AppletHeight -default 400] - - set host [ad_parameter ServerHost "" [ns_config "ns/server/[ns_info server]/module/nssock" Hostname]] - set port [parameter::get -parameter ServerPort -default 8200] - } } ad_return_template $template_use Index: openacs-4/packages/chat/www/room-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/room-postgresql.xql,v diff -u -N -r1.2.8.3 -r1.2.8.4 --- openacs-4/packages/chat/www/room-postgresql.xql 31 Aug 2016 09:58:39 -0000 1.2.8.3 +++ openacs-4/packages/chat/www/room-postgresql.xql 22 Nov 2016 18:34:35 -0000 1.2.8.4 @@ -4,10 +4,11 @@ - select pa.party_id, p.last_name || ', ' || p.first_names as name, pa.email + select pa.party_id, p.last_name || ', ' || p.first_names as name, pa.email from persons p, parties pa where p.person_id = pa.party_id - and acs_permission__permission_p(:room_id, pa.party_id, 'chat_ban') + and pa.party_id in + (select acs_permission.parties_with_object_privilege(:room_id::integer, 'chat_ban'::varchar)) order by p.last_name, p.first_names Index: openacs-4/packages/chat/www/room.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/room.tcl,v diff -u -N -r1.8.4.2 -r1.8.4.3 --- openacs-4/packages/chat/www/room.tcl 28 Oct 2016 18:57:36 -0000 1.8.4.2 +++ openacs-4/packages/chat/www/room.tcl 22 Nov 2016 18:34:35 -0000 1.8.4.3 @@ -63,8 +63,21 @@ from chat_rooms where room_id = :room_id" +# prettify flags +foreach property { + moderated_p + active_p + archive_p + auto_flush_p + auto_transcript_p + login_messages_p + logout_messages_p +} { + set $property [expr {[set $property] eq t?"[_ acs-kernel.common_yes]":"[_ acs-kernel.common_no]"}] +} + # get db-message count -set message_count [db_string message_count "select count(*) from chat_msgs where room_id = :room_id" -default 0] +set message_count [chat_message_count $room_id] # List user ban from chat db_multirow -extend {unban_url unban_text} banned_users list_user_ban {} { Index: openacs-4/packages/chat/www/ajax/chat.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/ajax/Attic/chat.js,v diff -u -N -r1.4.6.1 -r1.4.6.2 --- openacs-4/packages/chat/www/ajax/chat.js 28 Oct 2016 18:57:36 -0000 1.4.6.1 +++ openacs-4/packages/chat/www/ajax/chat.js 22 Nov 2016 18:34:35 -0000 1.4.6.2 @@ -57,13 +57,13 @@ p.className = 'line'; e = node.childNodes[i].getElementsByTagName('span'); span = doc.createElement('span'); - span.innerHTML = decodeURIComponent(e[0].firstChild.nodeValue); + span.innerHTML = e[0].innerHTML; span.className = 'timestamp'; p.appendChild(span); span = doc.createElement('span'); s = e[1].firstChild.nodeValue; - span.innerHTML = decodeURIComponent(e[1].firstChild.nodeValue.replace(/\+/g,' ')); + span.innerHTML = e[1].innerHTML; span.className = 'user'; p.appendChild(span); @@ -133,12 +133,12 @@ e = node.childNodes[i].getElementsByTagName('TD'); td = doc.createElement('td'); - td.innerHTML = decodeURIComponent(e[0].firstChild.nodeValue.replace(/\+/g,' ')); + td.innerHTML = e[0].innerHTML; td.className = 'user'; tr.appendChild(td); td = doc.createElement('td'); - td.innerHTML = decodeURIComponent(e[1].firstChild.nodeValue.replace(/\+/g,' ')); + td.innerHTML = e[1].innerHTML; td.className = 'timestamp'; tr.appendChild(td); @@ -176,7 +176,8 @@ obj.busy = false; } else { clearInterval(updateInterval); - alert('Something wrong in HTTP request, status code = ' + obj.connection.status); +// alert('Something wrong in HTTP request, status code = ' + obj.connection.status); + alert(obj.connection.responseText); } } }, Index: openacs-4/packages/chat/www/ajax/chat.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/ajax/Attic/chat.tcl,v diff -u -N -r1.4 -r1.4.6.1 --- openacs-4/packages/chat/www/ajax/chat.tcl 19 Nov 2007 01:14:17 -0000 1.4 +++ openacs-4/packages/chat/www/ajax/chat.tcl 22 Nov 2016 18:34:35 -0000 1.4.6.1 @@ -13,9 +13,12 @@ set ban_p [permission::permission_p -object_id $id -privilege "chat_ban"] if {$ban_p} { - ns_return 200 text/html "\ -
[_ chat.You_dont_have_permission_room]
\ - " + ns_return 200 text/html " + + \ +
[_ chat.You_dont_have_permission_room]
\ + + " ad_script_abort } @@ -26,31 +29,22 @@ switch -- $m { add_msg { - # i see no reason, why this is limited to 200 characters.... GN - # do not allow messages longer than 200 characters - #if { [string length $msg] > 200 } { - # set msg [string range $msg 0 200] - #} - # do not insert empty messages, if they managed to get here - if { $msg ne "" } { - set message_output [c1 add_msg $msg] - if { [c1 current_message_valid] } { - chat_message_post $id [c1 user_id] $msg 1 - } - } + set message_output [c1 add_msg $msg] } login - get_new - get_all { - set message_output [c1 $m] + set message_output [c1 $m] } get_updates { set message_output [c1 get_new] set user_output [c1 get_users] } get_users { - c1 encoder noencode - set user_output [c1 get_users] + c1 encoder noencode + set user_output [c1 get_users] } - default {ns_log error "--c unknown method $m called."} + default { + ns_log error "--c unknown method $m called." + } } set output " 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 -N -r1.23.2.5 -r1.23.2.6 --- openacs-4/packages/xotcl-core/tcl/chat-procs.tcl 11 Nov 2016 00:31:10 -0000 1.23.2.5 +++ openacs-4/packages/xotcl-core/tcl/chat-procs.tcl 22 Nov 2016 18:34:35 -0000 1.23.2.6 @@ -65,10 +65,10 @@ ::xo::clusterwide nsv_set $array-last-activity $user_id $now } - Chat instproc add_msg {{-get_new:boolean true} -uid msg} { + Chat instproc add_msg {{-get_new:boolean true} {-uid ""} msg} { my log "--chat adding $msg" my instvar array now - set user_id [expr {[info exists uid] ? $uid : [my set user_id]}] + set user_id [expr {$uid ne "" ? $uid : [my set user_id]}] set color [my user_color $user_id] set msg [ns_quotehtml $msg] # my log "-- msg=$msg"