Peter Alberer
Server based chat with an html and ajax client.
- 2006-04-06
+ 2006-04-11
OpenACS
Adapted by Peter Alberer 2006/03/25 to allow java and ajax to coexist.
Adapted by Tekne 2006/03/01 to replace JAVA server with AJAX; make use of generalized chat class from xotcl-core.
0
-
+
+
Index: openacs-4/packages/chat/lib/current-messages.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/lib/current-messages.tcl,v
diff -u -r1.1.2.2 -r1.1.2.3
--- openacs-4/packages/chat/lib/current-messages.tcl 7 Apr 2006 16:59:51 -0000 1.1.2.2
+++ openacs-4/packages/chat/lib/current-messages.tcl 11 Apr 2006 11:29:45 -0000 1.1.2.3
@@ -7,9 +7,7 @@
}
db_multirow -extend { person_name } messages select_msg_itens $sql {
- if { $creation_user eq 0 } {
- set person_name "Nobody"
- } else {
- set person_name [chat_user_name $creation_user]
+ if { [catch { set person_name [chat_user_name $creation_user] }] } {
+ set person_name "Unknown"
}
}
Index: openacs-4/packages/chat/sql/postgresql/upgrade/upgrade-5.0d4-5.0d5.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/sql/postgresql/upgrade/upgrade-5.0d4-5.0d5.sql,v
diff -u -r1.1.2.1 -r1.1.2.2
--- openacs-4/packages/chat/sql/postgresql/upgrade/upgrade-5.0d4-5.0d5.sql 7 Apr 2006 16:59:52 -0000 1.1.2.1
+++ openacs-4/packages/chat/sql/postgresql/upgrade/upgrade-5.0d4-5.0d5.sql 11 Apr 2006 11:29:46 -0000 1.1.2.2
@@ -1,8 +1,17 @@
-alter table chat_rooms add column auto_flush_p boolean default 't';
-alter table chat_rooms add column auto_transcript_p boolean default 'f';
+alter table chat_rooms add column auto_flush_p boolean;
+alter table chat_rooms alter column auto_flush_p set default 't';
+
+alter table chat_rooms add column auto_transcript_p boolean;
+alter table chat_rooms alter column auto_transcript_p set default 'f';
+
update chat_rooms set auto_flush_p = 't', auto_transcript_p = 'f';
+alter table chat_msgs add column creation_date2 timestamptz;
+update chat_msgs set creation_date2 = creation_date;
+alter table chat_msgs drop column creation_date;
+alter table chat_msgs rename column creation_date2 to creation_date;
+
create or replace function chat_room__edit (integer, varchar, varchar, boolean, boolean, boolean, boolean, boolean)
returns integer as '
declare
Index: openacs-4/packages/chat/tcl/chat-procs-postgresql.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/tcl/Attic/chat-procs-postgresql.xql,v
diff -u -r1.1.2.2 -r1.1.2.3
--- openacs-4/packages/chat/tcl/chat-procs-postgresql.xql 11 Apr 2006 07:59:01 -0000 1.1.2.2
+++ openacs-4/packages/chat/tcl/chat-procs-postgresql.xql 11 Apr 2006 11:29:46 -0000 1.1.2.3
@@ -121,7 +121,7 @@
perform chat_room__edit (
:room_id,
:pretty_name,
- :description,
+ :description,
:moderated_p,
:active_p,
:archive_p,
@@ -221,5 +221,23 @@
+
+
+ select room_id
+ from chat_rooms
+ where archive_p = 't' and auto_flush_p = 't'
+
+
+
+
+
+ select msg, creation_user, to_char(creation_date, 'DD.MM.YYYY hh24:mi:ss') as creation_date
+ from chat_msgs
+ where room_id = :room_id
+ and msg is not null
+ order by creation_date
+
+
+
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 -r1.5.2.3 -r1.5.2.4
--- openacs-4/packages/chat/tcl/chat-procs.tcl 11 Apr 2006 07:12:46 -0000 1.5.2.3
+++ openacs-4/packages/chat/tcl/chat-procs.tcl 11 Apr 2006 11:29:46 -0000 1.5.2.4
@@ -102,6 +102,9 @@
nsv_set chat_room $room_id {}
}
+ ns_log Notice "YY Adding message $msg to chat room $room_id"
+ ::chat::Chat c1 -volatile -chat_id $room_id -user_id 0 -session_id 0
+ c1 add_msg -uid $user_id $msg
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"
@@ -324,32 +327,32 @@
message
moderator_p
} {
- Post message to the chat room and broadcast to all applet clients. Only use by HTML client.
+ Post message to the chat room and broadcast to all applet clients. Used by ajax + html.
} {
if {$moderator_p == "1" } {
set status "approved"
} else {
set status "pending"
}
- # 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) eq "f" } { return }
-
set default_client [parameter::get -parameter "DefaultClient" -default "ajax"]
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
# broadcast message to applets.
-
nsv_set chat html_message $chat_msg
ns_mutex unlock [nsv_get chat new_message]
- } else {
+ }
+
+ # 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) eq "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"
}
- }
}
Index: openacs-4/packages/chat/www/chat.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/chat.tcl,v
diff -u -r1.5.2.3 -r1.5.2.4
--- openacs-4/packages/chat/www/chat.tcl 7 Apr 2006 16:59:52 -0000 1.5.2.3
+++ openacs-4/packages/chat/www/chat.tcl 11 Apr 2006 11:29:46 -0000 1.5.2.4
@@ -7,9 +7,9 @@
@creation-date November 22, 2000
@cvs-id $Id$
} {
- room_id
+ room_id
{client "ajax"}
- {message:html ""}
+ {message:html ""}
} -properties {
context_bar:onevalue
user_id:onevalue
@@ -32,9 +32,9 @@
set context_bar $room_name
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" } {
@@ -63,7 +63,7 @@
"html" {
set template_use "html-chat"
# forward to ajax if necessary
- if { ![empty_string_p $message] && [llength [info command ::chat::Chat]] > 0 } {
+ if { ![empty_string_p $message] } {
set session_id [ad_conn session_id]
::chat::Chat c1 -volatile -chat_id $room_id -session_id $session_id
c1 add_msg $message
Index: openacs-4/packages/chat/www/html-chat.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/Attic/html-chat.adp,v
diff -u -r1.5.2.1 -r1.5.2.2
--- openacs-4/packages/chat/www/html-chat.adp 30 Mar 2006 09:15:12 -0000 1.5.2.1
+++ openacs-4/packages/chat/www/html-chat.adp 11 Apr 2006 11:29:46 -0000 1.5.2.2
@@ -2,16 +2,39 @@
@context_bar;noquote@
@room_name;noquote@
+
+
+
#chat.Log_off#
#chat.Trascript#
-@richclient.title@
-
+@richclient.title@
+
-
-
Index: openacs-4/packages/chat/www/html-chat.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/Attic/html-chat.tcl,v
diff -u -r1.1.2.3 -r1.1.2.4
--- openacs-4/packages/chat/www/html-chat.tcl 10 Apr 2006 11:43:10 -0000 1.1.2.3
+++ openacs-4/packages/chat/www/html-chat.tcl 11 Apr 2006 11:29:46 -0000 1.1.2.4
@@ -27,18 +27,8 @@
ad_return_complaint 1 "[_ chat.Room_not_found]"
}
-template::list::create -name chat_msg \
- -multirow chat_msg_query \
- -no_data "[_ chat.no_messages]" \
- -page_flush_p 1 \
- -elements {
- creation_date_pretty { label "[_ chat.date]" }
- person_name { label "[_ acs-kernel.User]" }
- msg { label "[_ chat.msg]" }
- }
-
-db_multirow -extend { person_name } chat_msg_query select_msg_items {} {
- set person_name [person::name -person_id $creation_user]
-}
+::chat::Chat c1 -volatile -encoder noencode -chat_id $room_id
+set html_chat [c1 get_all]
+set html_users [c1 get_users]
ad_return_template
\ No newline at end of file
Index: openacs-4/packages/chat/www/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/index.tcl,v
diff -u -r1.3.2.3 -r1.3.2.4
--- openacs-4/packages/chat/www/index.tcl 7 Apr 2006 16:59:52 -0000 1.3.2.3
+++ openacs-4/packages/chat/www/index.tcl 11 Apr 2006 11:29:46 -0000 1.3.2.4
@@ -21,29 +21,18 @@
set default_client [parameter::get -parameter "DefaultClient" -default "ajax"]
set warning ""
-if { $default_client eq "ajax" } {
- if { ![apm_package_installed_p xotcl-core] } {
- set warning "[_ chat.xotcl_missing]"
- set default_client "html"
- } elseif { [llength [info command ::chat::Chat]] == 0 } {
- set warning "[_ chat.bootstrap_patch_missing]"
- set default_client "html"
- }
+if { $default_client eq "ajax" && ![apm_package_installed_p xotcl-core] } {
+ set warning "[_ chat.xotcl_missing]"
}
if { $room_create_p } {
lappend actions "#chat.Create_a_new_room#" room-edit "#chat.Create_a_new_room#"
}
db_multirow -extend { active_users last_activity } rooms rooms_list {} {
- if { [llength [info command ::chat::Chat]] > 0 } {
- set room [::chat::Chat create new -volatile -chat_id $room_id]
- set active_users [$room nr_active_users]
- set last_activity [$room last_activity]
- } else {
- set active_users "-"
- set last_activity "-"
- }
+ set room [::chat::Chat create new -volatile -chat_id $room_id]
+ set active_users [$room nr_active_users]
+ set last_activity [$room last_activity]
}
list::create \
Index: openacs-4/packages/chat/www/message-delete-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/message-delete-2.tcl,v
diff -u -r1.3.2.1 -r1.3.2.2
--- openacs-4/packages/chat/www/message-delete-2.tcl 30 Mar 2006 09:15:12 -0000 1.3.2.1
+++ openacs-4/packages/chat/www/message-delete-2.tcl 11 Apr 2006 11:29:46 -0000 1.3.2.2
@@ -15,8 +15,6 @@
ad_return_complaint 1 "[_ chat.Delete_messages_failed]: $errmsg"
}
-if { [llength [info command ::chat::Chat]] > 0 } {
- ::chat::Chat flush_messages -chat_id $room_id
-}
+::chat::Chat flush_messages -chat_id $room_id
ad_returnredirect .
\ No newline at end of file
Index: openacs-4/packages/chat/www/room-exit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/room-exit.tcl,v
diff -u -r1.3.2.1 -r1.3.2.2
--- openacs-4/packages/chat/www/room-exit.tcl 30 Mar 2006 09:15:12 -0000 1.3.2.1
+++ openacs-4/packages/chat/www/room-exit.tcl 11 Apr 2006 11:29:46 -0000 1.3.2.2
@@ -23,11 +23,9 @@
chat_message_post $room_id $user_id "[_ chat.has_left_the_room]." "1"
# send to AJAX
-if { [llength [info command ::chat::Chat]] > 0 } {
- set session_id [ad_conn session_id]
- ::chat::Chat c1 -volatile -chat_id $room_id -session_id $session_id
- c1 logout
-}
+set session_id [ad_conn session_id]
+::chat::Chat c1 -volatile -chat_id $room_id -session_id $session_id
+c1 logout
ad_returnredirect index
#ad_returnredirect [dotlrn::get_url]
Index: openacs-4/packages/chat/www/transcript-new-2.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/Attic/transcript-new-2.tcl,v
diff -u -r1.1.1.1.14.1 -r1.1.1.1.14.2
--- openacs-4/packages/chat/www/transcript-new-2.tcl 30 Mar 2006 09:15:12 -0000 1.1.1.1.14.1
+++ openacs-4/packages/chat/www/transcript-new-2.tcl 11 Apr 2006 11:29:46 -0000 1.1.1.1.14.2
@@ -27,9 +27,7 @@
if { $delete_messages eq "on" } {
chat_room_message_delete $room_id
# forward the information to AJAX
- if { [llength [info command ::chat::Chat]] > 0 } {
- ::chat::Chat flush_messages -chat_id $room_id
- }
+ ::chat::Chat flush_messages -chat_id $room_id
}
if { $deactivate_room eq "on" } {
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 -r1.1.2.5 -r1.1.2.6
--- openacs-4/packages/chat/www/ajax/chat.tcl 8 Apr 2006 09:14:20 -0000 1.1.2.5
+++ openacs-4/packages/chat/www/ajax/chat.tcl 11 Apr 2006 11:29:46 -0000 1.1.2.6
@@ -26,7 +26,7 @@
if { $msg ne "" } {
set message_output [c1 add_msg $msg]
if { [c1 current_message_valid] } {
- chat_message_post $id [c1 user_id] $msg f
+ chat_message_post $id [c1 user_id] $msg 1
}
}
}