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.23.2.15 -r1.23.2.16 --- openacs-4/packages/chat/tcl/chat-ajax-procs.tcl 8 Mar 2023 12:57:05 -0000 1.23.2.15 +++ openacs-4/packages/chat/tcl/chat-ajax-procs.tcl 13 Mar 2023 14:04:37 -0000 1.23.2.16 @@ -115,9 +115,24 @@ set uid [expr {$uid ne "" ? $uid : ${:user_id}}] - # Check write permissions + # + # Check write permissions for the chat user + # + if {[string is integer -strict $uid]} { + # + # The uid is an integer, that we expect to correspond to a + # party_id. + # + set party_id $uid + } else { + # + # The uid is another kind of anonymous identifier + # (e.g. the IP address). We map these to the public. + # + set party_id [acs_magic_object the_public] + } permission::require_permission \ - -party_id $uid \ + -party_id $party_id \ -object_id ${:chat_id} \ -privilege "chat_write" @@ -129,10 +144,16 @@ # code around expects the return value of the original method set retval [next] - # This way messages can be persisted immediately every time a - # message is sent + # + # Persist the chat message. We take note of the creation user, + # which may be The Public for anonymous participants and the + # IP address. + # if {[:current_message_valid]} { - $r post_message -msg $msg -creation_user $uid + $r post_message \ + -msg $msg \ + -creation_user $party_id \ + -creation_ip [ad_conn peeraddr] } return $retval 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 -r1.54.2.26 -r1.54.2.27 --- openacs-4/packages/xowiki/tcl/chat-procs.tcl 13 Mar 2023 12:03:23 -0000 1.54.2.26 +++ openacs-4/packages/xowiki/tcl/chat-procs.tcl 13 Mar 2023 14:04:37 -0000 1.54.2.27 @@ -41,6 +41,12 @@ set :now [clock clicks -milliseconds] if {![info exists :user_id]} { + # + # Chat may be instantiated outside xowiki, where ::xo::cc is + # assumed to exist. + # + ::xo::ConnectionContext require -url [ad_conn url] + set :user_id [ad_conn user_id] set :requestor [::xo::cc requestor] if {${:user_id} == 0} { @@ -92,6 +98,9 @@ if {![nsv_exists ${:array}-color idx]} { ::acs::clusterwide nsv_set ${:array}-color idx 0 } + if {![nsv_array exists ${:array}-anonymous_ids]} { + ::acs::clusterwide nsv_set ${:array}-anonymous_ids . . + } if {${:user_id} != 0 || [:session_id] != 0} { :init_user_color } @@ -286,13 +295,6 @@ Chat instproc login {} { :log "--chat login mode=${:mode}" if {${:login_messages_p} && ![:user_active ${:user_id}]} { - if {![nsv_array exists ${:array}-anonymous_ids]} { - # - # Create array in case it does not exist, since we need it in - # the next command. - # - ::acs::clusterwide nsv_set ${:array}-anonymous_ids . . - } :add_msg -uid ${:user_id} -get_new false [_ xotcl-core.has_entered_the_room] } elseif {${:user_id} > 0 && ![nsv_exists ${:array}-login ${:user_id}]} { # give some proof of our presence to the chat system when we @@ -666,7 +668,6 @@
- [ad_conn user_id] }] set conf [dict create] @@ -684,6 +685,10 @@ -conf $conf #:log "--CHAT created c1 with mode=$mode" + append html [subst { + [c1 set user_id] + }] + set js "" set data [c1 login] if {$data ne ""} { Index: openacs-4/packages/xowiki/www/resources/chat-common.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/Attic/chat-common.js,v diff -u -r1.10.2.12 -r1.10.2.13 --- openacs-4/packages/xowiki/www/resources/chat-common.js 3 Apr 2020 09:00:25 -0000 1.10.2.12 +++ openacs-4/packages/xowiki/www/resources/chat-common.js 13 Mar 2023 14:04:37 -0000 1.10.2.13 @@ -133,3 +133,28 @@ } } } + +function userLinkElement(user_id, current_user) { + let element; + let href; + + if (user_id == 0 || !Number.isInteger(user_id)) { + href = ''; + } else if (user_id != current_user) { + href = '/shared/community-member?user%5fid=' + user_id; + } else { + href = '/pvt/home'; + } + + if (href != "") { + element = document.createElement('a'); + element.href = href; + element.target = '_blank'; + } else { + element = document.createElement('span'); + } + + element.className = 'xowiki-chat-user-link'; + + return element; +} Index: openacs-4/packages/xowiki/www/resources/chat-skins/chat-bubbles.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/chat-skins/chat-bubbles.js,v diff -u -r1.1.2.4 -r1.1.2.5 --- openacs-4/packages/xowiki/www/resources/chat-skins/chat-bubbles.js 7 Mar 2019 12:57:47 -0000 1.1.2.4 +++ openacs-4/packages/xowiki/www/resources/chat-skins/chat-bubbles.js 13 Mar 2023 14:04:37 -0000 1.1.2.5 @@ -76,6 +76,7 @@ // Add terminator for the previous message block if exists if (previous_user_id != "") { + console.log('aaaa', previous_user_id, my_user_id); if (previous_user_id == my_user_id) { end_message = document.createElement('div'); end_message.className = 'xowiki-chat-message-block-end-me'; @@ -99,18 +100,19 @@ wrapper.className = 'xowiki-chat-user-pic-wrap'; if (show_avatar) { img = document.createElement('img'); - img.src = '/shared/portrait-bits.tcl?user_id=' + user_id + const imgHref = ((user_id == 0 || my_user_id == 0 + || !Number.isInteger(user_id) ) + ? '/shared/avatar-x50.png' + : "/shared/portrait-bits.tcl?user_id=" + user_id); + img.setAttribute("src", imgHref); img.className = 'xowiki-chat-user-pic'; img.style = 'border-color:' + color; wrapper.appendChild(img); } messages.appendChild(wrapper); // User link - a = document.createElement('a'); - a.href = '/shared/community-member?user%5fid=' + user_id; - a.target = '_blank'; - a.className = 'xowiki-chat-user-link'; + const a = userLinkElement(user_id, my_user_id); // User name span = document.createElement('span'); @@ -196,14 +198,7 @@ var color = msg.message[i].color; // User link - a = document.createElement('a'); - if (user_id != my_user_id) { - a.href = '/shared/community-member?user%5fid=' + user_id; - } else { - a.href = '/pvt/home'; - } - a.target = '_blank'; - a.className = 'xowiki-chat-user-link'; + const a = userLinkElement(user_id, my_user_id); // User block user_block = document.createElement('div'); @@ -215,7 +210,11 @@ wrapper = document.createElement('div'); wrapper.className = 'xowiki-chat-user-pic-wrap'; img = document.createElement('img'); - img.setAttribute("src", "/shared/portrait-bits.tcl?user_id=" + user_id); + let imgHref = ((user_id == 0 || my_user_id == 0 + || !Number.isInteger(user_id) ) + ? '/shared/avatar-x50.png' + : "/shared/portrait-bits.tcl?user_id=" + user_id); + img.setAttribute("src", imgHref); img.setAttribute("class", "xowiki-chat-user-pic"); img.setAttribute("style", "border-color:" + color); wrapper.appendChild(img); Index: openacs-4/packages/xowiki/www/resources/chat-skins/chat-classic.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/chat-skins/chat-classic.js,v diff -u -r1.1.2.5 -r1.1.2.6 --- openacs-4/packages/xowiki/www/resources/chat-skins/chat-classic.js 13 Mar 2023 12:03:24 -0000 1.1.2.5 +++ openacs-4/packages/xowiki/www/resources/chat-skins/chat-classic.js 13 Mar 2023 14:04:37 -0000 1.1.2.6 @@ -56,31 +56,6 @@ } } -function userLinkElement(user_id, current_user, where) { - let element; - let href; - - if (user_id == 0 || !isInteger(user_id)) { - href = ''; - } else if (user_id != current_user) { - href = '/shared/community-member?user%5fid=' + user_id; - } else { - href = '/pvt/home'; - } - //console.log(where + " user_id " + user_id + " current_user " + current_user + " -> " + href); - - if (href != "") { - element = document.createElement('a'); - element.href = href; - element.target = '_blank'; - element.className = 'xowiki-chat-user-link'; - } else { - element = document.createElement('span'); - } - return element; -} - - // Render the message function renderMessage(msg) { var messages = document.getElementById('xowiki-chat-messages'); @@ -96,7 +71,7 @@ user_block.className = 'xowiki-chat-user-block'; // User link - a = userLinkElement(user_id, my_user_id, 'message'); + a = userLinkElement(user_id, my_user_id); // User name span = document.createElement('span'); @@ -154,7 +129,7 @@ var user = msg.message[i].user.replace(/\\'/g, "\""); var user_id = msg.message[i].user_id; var color = msg.message[i].color; - let a = userLinkElement(user_id, my_user_id, 'userlist'); + let a = userLinkElement(user_id, my_user_id); // User block user_block = document.createElement('div'); @@ -169,7 +144,7 @@ // We do not have an image for an anonymous user, the // anonymous user cannot access the portrait bits. let imgHref = ((user_id == 0 || my_user_id == 0 - || !isInteger(user_id) ) + || !Number.isInteger(user_id) ) ? '/shared/avatar-x50.png' : "/shared/portrait-bits.tcl?user_id=" + user_id); img.setAttribute("src", imgHref); Index: openacs-4/packages/xowiki/www/resources/chat-skins/chat-minimal.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/chat-skins/chat-minimal.js,v diff -u -r1.1.2.2 -r1.1.2.3 --- openacs-4/packages/xowiki/www/resources/chat-skins/chat-minimal.js 7 Mar 2023 16:26:04 -0000 1.1.2.2 +++ openacs-4/packages/xowiki/www/resources/chat-skins/chat-minimal.js 13 Mar 2023 14:04:37 -0000 1.1.2.3 @@ -78,7 +78,11 @@ wrapper.className = 'xowiki-chat-user-pic-wrap'; if (show_avatar) { img = document.createElement('img'); - img.src = '/shared/portrait-bits.tcl?user_id=' + user_id + const imgHref = ((user_id == 0 || my_user_id == 0 + || !Number.isInteger(user_id) ) + ? '/shared/avatar-x50.png' + : "/shared/portrait-bits.tcl?user_id=" + user_id); + img.setAttribute("src", imgHref); img.className = 'xowiki-chat-user-pic'; img.style = 'border-color:' + color; wrapper.appendChild(img); @@ -90,14 +94,7 @@ user_block.className = 'xowiki-chat-user-block'; // User link - a = document.createElement('a'); - if (user_id != my_user_id) { - a.href = '/shared/community-member?user%5fid=' + user_id; - } else { - a.href = '/pvt/home'; - } - a.target = '_blank'; - a.className = 'xowiki-chat-user-link'; + const a = userLinkElement(user_id, my_user_id); // User name span = document.createElement('span');