瀏覽代碼

Add the ability to set the MUC domain to be used.

updates #203
JC Brand 8 年之前
父節點
當前提交
aad90cc9df
共有 3 個文件被更改,包括 38 次插入17 次删除
  1. 1 0
      docs/CHANGES.md
  2. 13 0
      docs/source/configuration.rst
  3. 24 17
      src/converse-muc.js

+ 1 - 0
docs/CHANGES.md

@@ -9,6 +9,7 @@
 - Start improving Content-Security-Policy compatibility by removing inline CSS. [mathiasertl]
 - Start improving Content-Security-Policy compatibility by removing inline CSS. [mathiasertl]
 - Add support for XEP-0048, chat room bookmarks [jcbrand]
 - Add support for XEP-0048, chat room bookmarks [jcbrand]
 - New configuration setting [connection_options](https://conversejs.org/docs/html/configuration.html#connection_options) [jcbrand]
 - New configuration setting [connection_options](https://conversejs.org/docs/html/configuration.html#connection_options) [jcbrand]
+- #203 New configuration setting [muc_domain](https://conversejs.org/docs/html/configuration.html#muc_domain) [jcbrand]
 
 
 ## 2.0.0 (2016-09-16)
 ## 2.0.0 (2016-09-16)
 - #656 Online users count not shown initially [amanzur]
 - #656 Online users count not shown initially [amanzur]

+ 13 - 0
docs/source/configuration.rst

@@ -515,6 +515,8 @@ fullname
 If you are using prebinding, can specify the fullname of the currently
 If you are using prebinding, can specify the fullname of the currently
 logged in user, otherwise the user's vCard will be fetched.
 logged in user, otherwise the user's vCard will be fetched.
 
 
+.. _`hide_muc_server`:
+
 hide_muc_server
 hide_muc_server
 ---------------
 ---------------
 
 
@@ -694,6 +696,17 @@ See also the `storage`_ option, which applies to other cached data, such as
 which chats you have open, what features the XMPP server supports and what
 which chats you have open, what features the XMPP server supports and what
 your online status is.
 your online status is.
 
 
+muc_domain
+----------
+
+* Default:  ``undefined``
+
+The MUC (multi-user chat) domain that should be used. By default converse.js
+will attempt to get the MUC domain from the XMPP host of the currently logged in
+user.
+
+This setting will override that. You might want to combine this setting with `hide_muc_server`_.
+
 muc_history_max_stanzas
 muc_history_max_stanzas
 -----------------------
 -----------------------
 
 

+ 24 - 17
src/converse-muc.js

@@ -146,33 +146,39 @@
                 },
                 },
 
 
                 onConnected: function () {
                 onConnected: function () {
-                    // TODO: This can probably be refactored to be an event
-                    // handler (and therefore removed from overrides)
                     var converse = this.__super__.converse;
                     var converse = this.__super__.converse;
                     this.__super__.onConnected.apply(this, arguments);
                     this.__super__.onConnected.apply(this, arguments);
 
 
-                    if (this.model.get('connected')) {
-                        converse.features.off('add', this.featureAdded, this);
-                        converse.features.on('add', this.featureAdded, this);
-                        // Features could have been added before the controlbox was
-                        // initialized. We're only interested in MUC
-                        var feature = converse.features.findWhere({
-                            'var': Strophe.NS.MUC
-                        });
-                        if (feature) {
-                            this.featureAdded(feature);
+                    if (_.isUndefined(converse.muc_domain)) {
+                        if (this.model.get('connected')) {
+                            converse.features.off('add', this.featureAdded, this);
+                            converse.features.on('add', this.featureAdded, this);
+                            // Features could have been added before the controlbox was
+                            // initialized. We're only interested in MUC
+                            var feature = converse.features.findWhere({
+                                'var': Strophe.NS.MUC
+                            });
+                            if (feature) {
+                                this.featureAdded(feature);
+                            }
                         }
                         }
+                    } else {
+                        this.setMUCDomain(converse.muc_domain);
+                    }
+                },
+
+                setMUCDomain: function (domain) {
+                    this.roomspanel.model.save({'muc_domain': domain});
+                    var $server= this.$el.find('input.new-chatroom-server');
+                    if (!$server.is(':focus')) {
+                        $server.val(this.roomspanel.model.get('muc_domain'));
                     }
                     }
                 },
                 },
 
 
                 featureAdded: function (feature) {
                 featureAdded: function (feature) {
                     var converse = this.__super__.converse;
                     var converse = this.__super__.converse;
                     if ((feature.get('var') === Strophe.NS.MUC) && (converse.allow_muc)) {
                     if ((feature.get('var') === Strophe.NS.MUC) && (converse.allow_muc)) {
-                        this.roomspanel.model.save({muc_domain: feature.get('from')});
-                        var $server= this.$el.find('input.new-chatroom-server');
-                        if (! $server.is(':focus')) {
-                            $server.val(this.roomspanel.model.get('muc_domain'));
-                        }
+                        this.setMUCDomain(feature.get('from'));
                     }
                     }
                 }
                 }
             },
             },
@@ -206,6 +212,7 @@
                 auto_join_rooms: [],
                 auto_join_rooms: [],
                 auto_list_rooms: false,
                 auto_list_rooms: false,
                 hide_muc_server: false,
                 hide_muc_server: false,
+                muc_domain: undefined,
                 muc_history_max_stanzas: undefined,
                 muc_history_max_stanzas: undefined,
                 muc_instant_rooms: true,
                 muc_instant_rooms: true,
                 muc_nickname_from_jid: false
                 muc_nickname_from_jid: false