Bläddra i källkod

Add new MUC option `auto_join_rooms`.

Fixes #156
JC Brand 9 år sedan
förälder
incheckning
946e9fed5d
3 ändrade filer med 34 tillägg och 5 borttagningar
  1. 3 1
      docs/CHANGES.md
  2. 17 0
      docs/source/configuration.rst
  3. 14 4
      src/converse-muc.js

+ 3 - 1
docs/CHANGES.md

@@ -1,6 +1,6 @@
 # Changelog
 
-## 0.11.0 (Unreleased)
+## 1.0.0 (Unreleased)
 
 - Add support for messages with type `headline`, often used for notifications
   from the server. [jcbrand]
@@ -18,6 +18,8 @@
 - Use `rel=noopener` with links that contain `target=_blank` to prevent potential
   phishing attacks. [More info here](https://mathiasbynens.github.io/rel-noopener/)
   [jcbrand]
+- #156 Add the option `auto_join_rooms` which allows you to automatically
+  connect to certain rooms once logged in. [jcbrand]
 - #261 `show_controlbox_by_default` config not working [diditopher]
 - #443 HTML5 notifications of received messages [jcbrand]
 - #534 Updated Russian translation [badfiles]

+ 17 - 0
docs/source/configuration.rst

@@ -256,6 +256,23 @@ auto_join_on_invite
 
 If true, the user will automatically join a chatroom on invite without any confirm.
 
+
+auto_join_rooms
+---------------
+
+* Default:  ``[]``
+
+This settings allows you to provide a list of groupchat conversations to be
+automatically joined once the user has logged in.
+
+You can either specify a simple list of room JIDs, in which case your nickname
+will be taken from your JID, or you can specify a list of maps, where each map
+specifies the room's JID and the nickname that should be used.
+
+For example:
+
+    `[{'jid': 'room@example.org', 'nick': 'WizardKing69' }]`
+
 .. _`bosh-service-url`:
 
 bosh_service_url

+ 14 - 4
src/converse-muc.js

@@ -150,7 +150,8 @@
             this.updateSettings({
                 allow_muc: true,
                 auto_join_on_invite: false,  // Auto-join chatroom on invite
-                auto_join_rooms: [], // List of JIDs of rooms to be joined upon login
+                auto_join_rooms: [], // List of maps {'jid': 'room@example.org', 'nick': 'WizardKing69' },
+                                     // providing room jids and nicks or simply a list JIDs.
                 auto_list_rooms: false,
                 hide_muc_server: false,
                 muc_history_max_stanzas: undefined, // Takes an integer, limits the amount of messages to fetch from chat room's history
@@ -1327,15 +1328,24 @@
                     }
                 }
             };
-            var registerInviteHandler = function () {
+            var onConnected = function () {
                 converse.connection.addHandler(
                     function (message) {
                         converse.onDirectMUCInvitation(message);
                         return true;
                     }, 'jabber:x:conference', 'message');
+                _.each(converse.auto_join_rooms, function (room) {
+                    if (typeof room === 'string') {
+                        converse_api.rooms.open(room);
+                    } else if (typeof room === 'object') {
+                        converse_api.rooms.open(room.jid, room.nick);
+                    } else {
+                        converse.log('Invalid room criteria specified for "auto_join_rooms"', 'error');
+                    }
+                });
             };
-            converse.on('connected', registerInviteHandler);
-            converse.on('reconnected', registerInviteHandler);
+            converse.on('connected', onConnected);
+            converse.on('reconnected', onConnected);
             /* ------------------------------------------------------------ */