Class ::xo::ChatClass (public)
::xotcl::Class ::xo::ChatClass
Defined in
- Testcases:
-
No testcase defined.
Source code:
namespace eval ::xo {}
::nsf::object::alloc ::xotcl::Class ::xo::ChatClass {set :__default_metaclass ::xotcl::Class
set :__default_superclass ::xotcl::Object}
::xo::ChatClass proc is_chat_p class {
return [expr {[nsf::is object $class] && [$class class] eq [self]}]
}
::xo::ChatClass instproc init {} {
set :colors [list #1b9e77 #d95f02 #7570b3 #e7298a #66a61e #e6ab02 #a6761d #666666]
}
::xo::ChatClass instproc flush_messages -chat_id:required {
set array "[self]-$chat_id"
::acs::clusterwide nsv_unset -nocomplain $array
::acs::clusterwide nsv_unset -nocomplain $array-seen
::acs::clusterwide nsv_unset -nocomplain $array-last-activity
}
::xo::ChatClass instproc login {-chat_id:required {-skin "classic"} {-package_id ""} {-mode ""} {-path ""} {-avatar_p:boolean true} {-force_login_p:boolean false} -login_messages_p:boolean -logout_messages_p:boolean -timewindow} {
if {![ns_conn isconnected]} {
return
}
if {$force_login_p} {
auth::require_login
}
template::head::add_css -href /resources/xowiki/chat-skins/chat-$skin.css
if {[info commands ::thread::mutex] eq "" ||
[catch {ns_conn contentsentlength}]} {
set mode polling
}
set session_id [ad_conn session_id].[clock seconds]
set base_url [export_vars -base /shared/ajax/chat -no_empty {
{id $chat_id} {s $session_id} {class "[self]"} mode
}]
set link_regex [::parameter::get_global_value -package_key "chat" -parameter "LinkRegex"]
set fs_link_p true
if {$avatar_p} {
set show_avatar true
} else {
set show_avatar false
}
template::head::add_javascript -script "const linkRegex = \"${link_regex}\";" -order 19
template::head::add_javascript -script "const show_avatar = $show_avatar;" -order 20
template::head::add_javascript -src /resources/xowiki/chat-skins/chat-$skin.js -order 22
template::head::add_javascript -src /resources/xowiki/chat.js -order 30
set html ""
if {[apm_package_installed_p chat]} {
set message_label [_ xowiki.chat_message]
set send_label [_ xowiki.chat_Send_Refresh]
} else {
set message_label "Message"
set send_label "Send"
}
append html [subst {
<div id='xowiki-chat'>
<div id='xowiki-chat-messages-and-form'>
<div id='xowiki-chat-messages'></div>
<div id='xowiki-chat-messages-form-block'>
<form id='xowiki-chat-messages-form' action='#'>
<input type='text' placeholder="$message_label" name='msg' id='xowiki-chat-send' autocomplete="off" />
<button id='xowiki-chat-send-button' type='submit'>$send_label</button>
</form>
</div>
</div>
<div id='xowiki-chat-users'></div>
</div>
}]
set conf [dict create]
foreach var {force_login_p login_messages_p logout_messages_p timewindow} {
if {[info exists $var]} {
dict set conf $var [set $var]
}
}
:create c1 -chat_id $chat_id -session_id $session_id -mode $mode -conf $conf -destroy_on_cleanup
append html [subst {
<span id="xowiki-my-user-id" style="display:none;">[c1 set user_id]</span>
}]
set js ""
set data [c1 login]
if {$data ne ""} {
append js [subst -nocommands {
let data = $data;
for (var i = 0; i < data.length; i++) {
renderData(data[i]);
}
}]
}
if {$fs_link_p} {
append js {addFullScreenLink();}
}
append js {addSendPic();}
append js [subst {
chatSubscribe('$base_url');
}]
append html [subst {
<script nonce="[security::csp::nonce]">
$js
</script>
}]
template::add_refresh_on_history_handler
return $html
}
::xo::ChatClass instproc sweep_all_chats {} {
foreach nsv [nsv_names "[self]-*-seen"] {
if { [regexp "[self]-(\[0-9\]+)-seen" $nsv _ chat_id] } {
:new -volatile -chat_id $chat_id -user_id 0 -session_id 0 -init -sweeper
}
}
}
::xo::ChatClass instproc initialize_nsvs {} {
}
::nsf::relation::set ::xo::ChatClass superclass ::xotcl::Class
XQL Not present:Generic, PostgreSQL, Oracle
[
hide source ]
| [
make this the default ]