浏览代码

bookmarks: Don't autojoin rooms prematurely

by first waiting until chatboxes have been fetched as well.
JC Brand 8 年之前
父节点
当前提交
3835ab7af6
共有 3 个文件被更改,包括 8 次插入2 次删除
  1. 1 0
      docs/source/developer_api.rst
  2. 2 1
      src/converse-bookmarks.js
  3. 5 1
      src/converse-muc.js

+ 1 - 0
docs/source/developer_api.rst

@@ -189,6 +189,7 @@ Converse.js has the following promises:
 * rosterGroupsFetched
 * rosterInitialized
 * statusInitialized
+* roomsPanelRendered (only via the `converse-muc` plugin)
 
 Below is an example from `converse-muc.js <https://github.com/jcbrand/converse.js/blob/master/src/converse-muc.js>`_
 where the `rosterContactsFetched` promise is waited on. The method

+ 2 - 1
src/converse-bookmarks.js

@@ -470,7 +470,8 @@
                 });
                 _converse.emit('bookmarksInitialized');
             };
-            _converse.on('roomsPanelRendered', initBookmarks);
+            $.when(_converse.api.waitUntil('chatBoxesFetched'),
+                   _converse.api.waitUntil('roomsPanelRendered')).then(initBookmarks);
 
             var afterReconnection = function () {
                 if (!_converse.allow_bookmarks) {

+ 5 - 1
src/converse-muc.js

@@ -319,6 +319,10 @@
                 },
             });
 
+            _.extend(_converse.promises, {
+                'roomsPanelRendered': new $.Deferred()
+            });
+
             _converse.createChatRoom = function (settings) {
                 /* Creates a new chat room, making sure that certain attributes
                  * are correct, for example that the "type" is set to
@@ -385,7 +389,7 @@
                         });
                     } else {
                         this.fetchMessages();
-                        _converse.emit('chatRoomOpened', that);
+                        _converse.emit('chatRoomOpened', this);
                     }
                 },