Selaa lähdekoodia

Update 'rooms' api to allow user to pass in room attributes.

JC Brand 9 vuotta sitten
vanhempi
commit
95a0b91afa
2 muutettua tiedostoa jossa 24 lisäystä ja 15 poistoa
  1. 3 3
      src/converse-core.js
  2. 21 12
      src/converse-muc.js

+ 3 - 3
src/converse-core.js

@@ -1396,7 +1396,7 @@
                 return true;
             },
 
-            getChatBox: function (jid, create) {
+            getChatBox: function (jid, create, attrs) {
                 /* Returns a chat box or optionally return a newly
                  * created one if one doesn't exist.
                  *
@@ -1413,14 +1413,14 @@
                         converse.log('Could not get roster item for JID '+bare_jid, 'error');
                         return;
                     }
-                    chatbox = this.create({
+                    chatbox = this.create(_.extend({
                         'id': bare_jid,
                         'jid': bare_jid,
                         'fullname': _.isEmpty(roster_item.get('fullname'))? jid: roster_item.get('fullname'),
                         'image_type': roster_item.get('image_type'),
                         'image': roster_item.get('image'),
                         'url': roster_item.get('url')
-                    });
+                    }, attrs || {}));
                 }
                 return chatbox;
             }

+ 21 - 12
src/converse-muc.js

@@ -1602,16 +1602,15 @@
             }
             /* ------------------------------------------------------------ */
 
-            var _transform = function (jid, nick, fetcher) {
+            var _transform = function (jid, attrs, fetcher) {
                 jid = jid.toLowerCase();
-                return converse.wrappedChatBox(fetcher({
+                return converse.wrappedChatBox(fetcher(_.extend({
                     'id': jid,
                     'jid': jid,
                     'name': Strophe.unescapeNode(Strophe.getNodeFromJid(jid)),
-                    'nick': nick,
                     'type': 'chatroom',
                     'box_id': b64_sha1(jid)
-                }));
+                }, attrs)));
             };
 
 
@@ -1637,16 +1636,26 @@
                             });
                         }
                     },
-                    'open': function (jids, nick) {
+                    'open': function (jids, attrs) {
+                        if (typeof attrs === "string") {
+                            attrs = {'nick': attrs};
+                        } else if (typeof attrs === "undefined") {
+                            attrs = {};
+                        }
                         var fetcher = converse.chatboxviews.showChat.bind(converse.chatboxviews);
                         if (typeof jids === "undefined") {
                             throw new TypeError('rooms.open: You need to provide at least one JID');
                         } else if (typeof jids === "string") {
-                            return _transform(jids, nick, fetcher);
+                            return _transform(jids, attrs, fetcher);
                         }
-                        return _.map(jids, _.partial(_transform, _, nick, fetcher));
+                        return _.map(jids, _.partial(_transform, _, attrs, fetcher));
                     },
-                    'get': function (jids, nick, create) {
+                    'get': function (jids, attrs, create) {
+                        if (typeof attrs === "string") {
+                            attrs = {'nick': attrs};
+                        } else if (typeof attrs === "undefined") {
+                            attrs = {};
+                        }
                         if (typeof jids === "undefined") {
                             var result = [];
                             converse.chatboxes.each(function (chatbox) {
@@ -1657,13 +1666,13 @@
                             return result;
                         }
                         var fetcher = _.partial(converse.chatboxviews.getChatBox.bind(converse.chatboxviews), _, create);
-                        if (!nick) {
-                            nick = Strophe.getNodeFromJid(converse.bare_jid);
+                        if (!attrs.nick) {
+                            attrs.nick = Strophe.getNodeFromJid(converse.bare_jid);
                         }
                         if (typeof jids === "string") {
-                            return _transform(jids, nick, fetcher);
+                            return _transform(jids, attrs, fetcher);
                         }
-                        return _.map(jids, _.partial(_transform, _, nick, fetcher));
+                        return _.map(jids, _.partial(_transform, _, attrs, fetcher));
                     }
                 }
             });