Quellcode durchsuchen

Always uses 8 hex digits for the MUC nickname/endpoint ID. (#921)

* Always uses 8 hex digits for the MUC nickname/endpoint ID.

* squash: Fix a comment and add the full JID to the log.

* squash: Fixes the compilation and style.
dev1
bgrozev vor 6 Jahren
Ursprung
Commit
647a48bf4d
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden
1 geänderte Dateien mit 19 neuen und 14 gelöschten Zeilen
  1. 19
    14
      modules/xmpp/xmpp.js

+ 19
- 14
modules/xmpp/xmpp.js Datei anzeigen

413
      * @param options
413
      * @param options
414
      */
414
      */
415
     createRoom(roomName, options) {
415
     createRoom(roomName, options) {
416
-        // By default MUC nickname is the resource part of the JID
417
-        let mucNickname = Strophe.getNodeFromJid(this.connection.jid);
418
         let roomjid = `${roomName}@${this.options.hosts.muc}/`;
416
         let roomjid = `${roomName}@${this.options.hosts.muc}/`;
419
-        const cfgNickname
420
-            = options.useNicks && options.nick ? options.nick : null;
421
 
417
 
422
-        if (cfgNickname) {
423
-            // Use nick if it's defined
424
-            mucNickname = options.nick;
418
+        let mucNickname;
419
+
420
+        // We use the room nickname (the resourcepart of the occupant JID, see XEP-0045)
421
+        // as the endpoint ID in colibri. We require endpoint IDs to be 8 hex digits because
422
+        // in some cases they get serialized into a 32bit field.
423
+        if (this.authenticatedUser) {
424
+            // For authenticated users generate a random ID.
425
+            mucNickname = RandomUtil.randomHexString(8).toLowerCase();
425
         } else if (!this.authenticatedUser) {
426
         } else if (!this.authenticatedUser) {
426
-            // node of the anonymous JID is very long - here we trim it a bit
427
-            mucNickname = mucNickname.substr(0, 8);
428
-        }
427
+            // We try to use the first part of the node (which for anonymous users on prosody is a UUID) to match
428
+            // the previous behavior (and maybe make debugging easier).
429
+            mucNickname = Strophe.getNodeFromJid(this.connection.jid).substr(0, 8)
430
+                .toLowerCase();
429
 
431
 
430
-        // Constant JIDs need some random part to be appended in order to be
431
-        // able to join the MUC more than once.
432
-        if (this.authenticatedUser || cfgNickname !== null) {
433
-            mucNickname += `-${RandomUtil.randomHexString(6)}`;
432
+            // But if this doesn't have the required format we just generate a new random nickname.
433
+            const re = /[0-9a-f]{8}/g;
434
+
435
+            if (!re.test(mucNickname)) {
436
+                mucNickname = RandomUtil.randomHexString(8).toLowerCase();
437
+            }
434
         }
438
         }
435
 
439
 
440
+        logger.info(`JID ${this.connection.jid} using MUC nickname $mucNickname`);
436
         roomjid += mucNickname;
441
         roomjid += mucNickname;
437
 
442
 
438
         return this.connection.emuc.createRoom(roomjid, null, options);
443
         return this.connection.emuc.createRoom(roomjid, null, options);

Laden…
Abbrechen
Speichern