瀏覽代碼

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

tags/v0.0.2
paweldomas 9 年之前
父節點
當前提交
b85602c90a
共有 1 個文件被更改,包括 18 次插入3 次删除
  1. 18
    3
      modules/xmpp/xmpp.js

+ 18
- 3
modules/xmpp/xmpp.js 查看文件

242
     }
242
     }
243
 
243
 
244
     createRoom (roomName, options, settings) {
244
     createRoom (roomName, options, settings) {
245
+        // By default MUC nickname is the resource part of the JID
245
         let mucNickname = Strophe.getNodeFromJid(this.connection.jid);
246
         let mucNickname = Strophe.getNodeFromJid(this.connection.jid);
246
         let roomjid = roomName  + "@" + this.options.hosts.muc + "/";
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
         return this.connection.emuc.createRoom(roomjid, null, options,
266
         return this.connection.emuc.createRoom(roomjid, null, options,
252
             settings);
267
             settings);
253
     }
268
     }

Loading…
取消
儲存