[TikiWiki-commits] [Git][tikiwiki/tiki][master] [ENH] XMPP: add optional custom nickname for anonymous visitors

"John Livingston \(@JohnXLivingston\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a229c5ef391b_381945ec4239@gitlab-sidekiq-low-urgency-cpu-bound-v2-849c9f545-hctcf.mail>

John Livingston pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
fa45ea47 by Olivier Kango at 2026-06-05T11:35:25+02:00
[ENH] XMPP: add optional custom nickname for anonymous visitors
---
* [FIX] XMPP: restrict nickname clash override to anonymous users

* [FIX] auto-increment nickname on MUC conflict instead of prompting user

* [ENH] XMPP: add optional custom nickname for anonymous visitors

See merge request tikiwiki/tiki!10152

- - - - -


4 changed files:

- lib/prefs/xmpp.php
- lib/xmpp/ConverseJS.php
- lib/xmpp/js/conversejs-tiki.js
- templates/admin/include_rtc.tpl


Changes:

=====================================
lib/prefs/xmpp.php
=====================================
@@ -167,6 +167,13 @@ function prefs_xmpp_list()
             'default' => 'community',
             'tags' => ['basic'],
         ],
+        'xmpp_anonymous_allow_custom_nickname' => [
+            'name' => tra('Allow anonymous visitors to choose a nickname'),
+            'description' => tra('When enabled, anonymous visitors are prompted to choose their chat nickname before sending messages. When disabled, Tiki uses an automatic visitor nickname.'),
+            'type' => 'flag',
+            'tags' => ['basic'],
+            'default' => 'n',
+        ],
         'xmpp_ws_url' => [
             'name' => tra('XMPP WebSocket URL'),
             'description' => tra('WebSocket endpoint for ConverseJS. If set, this takes precedence over the BOSH (http-bind) URL.'),


=====================================
lib/xmpp/ConverseJS.php
=====================================
@@ -98,12 +98,13 @@ class ConverseJS
             }
 
             $this->set_options([
-                'authentication'   => 'anonymous',
-                'auto_login'       => true,
-                'jid'              => $prefs['xmpp_domain_guest'] ?? null,
-                'bosh_service_url' => $prefs['xmpp_server_http_bind'] ?? null,
-                'websocket_url'    => $prefs['xmpp_ws_url'] ?? null,
-                'dm_target'        => $dmTarget,
+                'authentication'      => 'anonymous',
+                'auto_login'          => true,
+                'jid'                 => $prefs['xmpp_domain_guest'] ?? null,
+                'bosh_service_url'    => $prefs['xmpp_server_http_bind'] ?? null,
+                'websocket_url'       => $prefs['xmpp_ws_url'] ?? null,
+                'dm_target'           => $dmTarget,
+                'tiki_anonymous_nick' => ($prefs['xmpp_anonymous_allow_custom_nickname'] ?? 'n') === 'y' ? 'custom' : 'visitor',
             ]);
 
             // Auto-join anonymous room if configured (community only)


=====================================
lib/xmpp/js/conversejs-tiki.js
=====================================
@@ -12,10 +12,18 @@
         "initialize": function () {
             _converse = this._converse;
 
+            // Declare custom Tiki settings so api.settings.get() can read values passed from PHP
+            _converse.api.settings.extend({
+                dm_target: null,
+                anonymous: null,
+                tiki_anonymous_nick: 'visitor',
+            });
+
             // Store Tiki-provided settings for later use (DM target, anon flag)
             _converse.tikiSettings = {
                 dm_target: _converse.api.settings.get('dm_target'),
                 anonymous: _converse.api.settings.get('anonymous'),
+                anonymous_nick: _converse.api.settings.get('tiki_anonymous_nick') || 'visitor',
             };
             var error = console && console.error // eslint-disable-line no-console
                 ? console.error.bind(console) // eslint-disable-line no-console
@@ -51,6 +59,11 @@
                             return originalGetDefaultMUCNickname.apply(this, args);
                         }
 
+                        // If admin allows custom nickname, let ConverseJS prompt the user natively
+                        if (_converse.tikiSettings.anonymous_nick === 'custom') {
+                            return originalGetDefaultMUCNickname.apply(this, args);
+                        }
+
                         const previousNick = (typeof getPreviousAnonymousNick === 'function')
                             ? getPreviousAnonymousNick()
                             : null;
@@ -59,7 +72,6 @@
                             ? randomNick('visitor')
                             : 'visitor-' + Math.floor(Math.random() * 100000);
 
-                        // Try Converse default first
                         return (
                             originalGetDefaultMUCNickname.apply(this, args) ||
                             previousNick ||
@@ -189,6 +201,26 @@
         },
 
         "overrides": {
+            "ChatRoom": {
+                // Auto-increment anonymous nicknames on conflict instead of prompting the user.
+                "onNicknameClash": function (presence) {
+                    if (_converse.api.settings.get('authentication') !== 'anonymous') {
+                        return this.__super__.onNicknameClash.apply(this, arguments);
+                    }
+
+                    const attemptedNick = (presence.getAttribute('from') || '').split('/')[1];
+                    if (!attemptedNick) {
+                        return this.__super__.onNicknameClash.apply(this, arguments);
+                    }
+                    const lastDash = attemptedNick.lastIndexOf('-');
+                    const suffix = lastDash !== -1 ? attemptedNick.substring(lastDash + 1) : '';
+                    const num = parseInt(suffix, 10);
+                    const newNick = !isNaN(num) && suffix !== ''
+                        ? attemptedNick.substring(0, lastDash + 1) + (num + 1)
+                        : attemptedNick + '-2';
+                    this.join(newNick);
+                },
+            },
             "Bookmarks": {
                 "openBookmarkedRoom":  async function (bookmark) {
                     if (bookmark.get('autojoin')) {


=====================================
templates/admin/include_rtc.tpl
=====================================
@@ -52,6 +52,7 @@
                     {preference name=xmpp_domain_users}
                     {preference name=xmpp_domain_guest}
                     {preference name=xmpp_anonymous_mode}
+                    {preference name=xmpp_anonymous_allow_custom_nickname}
                     {preference name=xmpp_anonymous_room}
                     {preference name=xmpp_anonymous_support_room}
                     {preference name=xmpp_registered_room}



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/fa45ea47bb19c201e4543e0a88ad4df7fa127036

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/fa45ea47bb19c201e4543e0a88ad4df7fa127036
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.