Explorar el Código

fix(xmpp.js): logic around constant MUC nicknames

tags/v0.0.2
paweldomas hace 9 años
padre
commit
b85602c90a
Se han modificado 1 ficheros con 18 adiciones y 3 borrados
  1. 18
    3
      modules/xmpp/xmpp.js

+ 18
- 3
modules/xmpp/xmpp.js Ver fichero

@@ -242,12 +242,27 @@ export default class XMPP {
242 242
     }
243 243
 
244 244
     createRoom (roomName, options, settings) {
245
+        // By default MUC nickname is the resource part of the JID
245 246
         let mucNickname = Strophe.getNodeFromJid(this.connection.jid);
246 247
         let roomjid = roomName  + "@" + this.options.hosts.muc + "/";
248
+        let cfgNickname
249
+            = (options.useNicks && options.nick) ? options.nick : null;
250
+
251
+        if (cfgNickname) {
252
+            // Use nick if it's defined
253
+            mucNickname = options.nick;
254
+        } else if (!this.authenticatedUser) {
255
+            // node of the anonymous JID is very long - here we trim it a bit
256
+            mucNickname = mucNickname.substr(0, 8);
257
+        }
258
+        // Constant JIDs need some random part to be appended in order to be
259
+        // able to join the MUC more than once.
260
+        if (this.authenticatedUser || cfgNickname != null) {
261
+            mucNickname += "-" + RandomUtil.randomHexString(6);
262
+        }
263
+
264
+        roomjid += mucNickname;
247 265
 
248
-        roomjid += (options.useNicks) ? options.nick || mucNickname :
249
-            (this.authenticatedUser ? "-" + RandomUtil.randomHexString(6):
250
-                mucNickname.substr(0, 8));
251 266
         return this.connection.emuc.createRoom(roomjid, null, options,
252 267
             settings);
253 268
     }

Loading…
Cancelar
Guardar