Преглед изворни кода

Add a "create" parameter to rooms.get

to indicate whether the room should be created if not found.
JC Brand пре 9 година
родитељ
комит
10ca2900d4
3 измењених фајлова са 17 додато и 6 уклоњено
  1. 12 1
      docs/source/development.rst
  2. 3 3
      src/converse-core.js
  3. 2 2
      src/converse-muc.js

+ 12 - 1
docs/source/development.rst

@@ -651,8 +651,19 @@ get
 ~~~
 
 Returns an object representing a multi user chat box (room).
+It takes 3 parameters:
 
-Similar to chats.get API
+* the room JID
+* the user's nickname (if not specified, the node part of the user's JID will be used).
+* boolean, indicating whether the room should be created if not found (default: `false`)
+
+The last two parameters are optional.
+
+.. code-block:: javascript
+
+    var nick = 'dread-pirate-roberts';
+    var create_if_not_found = true;
+    converse.rooms.open('group@muc.example.com', nick, create_if_not_found)
 
 open
 ~~~~

+ 3 - 3
src/converse-core.js

@@ -1437,9 +1437,9 @@
                 return this.model.chatBoxMayBeShown(chatbox);
             },
 
-            getChatBox: function (attrs) {
+            getChatBox: function (attrs, create) {
                 var chatbox  = this.model.get(attrs.jid);
-                if (!chatbox) {
+                if (!chatbox && create) {
                     chatbox = this.model.create(attrs, {
                         'error': function (model, response) {
                             converse.log(response.responseText);
@@ -1453,7 +1453,7 @@
                 /* Find the chat box and show it (if it may be shown).
                  * If it doesn't exist, create it.
                  */
-                var chatbox = this.getChatBox(attrs);
+                var chatbox = this.getChatBox(attrs, true);
                 if (this.chatBoxMayBeShown(chatbox)) {
                     chatbox.trigger('show', true);
                 }

+ 2 - 2
src/converse-muc.js

@@ -1431,8 +1431,8 @@
                         }
                         return _.map(jids, _.partial(_transform, _, nick, fetcher));
                     },
-                    'get': function (jids, nick) {
-                        var fetcher = converse.chatboxviews.getChatBox.bind(converse.chatboxviews);
+                    'get': function (jids, nick, create) {
+                        var fetcher = _.partial(converse.chatboxviews.getChatBox.bind(converse.chatboxviews), _, create);
                         if (!nick) {
                             nick = Strophe.getNodeFromJid(converse.bare_jid);
                         }