Explorar o código

Use async/await for `enterRoom`

JC Brand %!s(int64=6) %!d(string=hai) anos
pai
achega
0ee08ee622
Modificáronse 2 ficheiros con 18 adicións e 25 borrados
  1. 10 14
      dist/converse.js
  2. 8 11
      src/converse-muc-views.js

+ 10 - 14
dist/converse.js

@@ -53709,30 +53709,26 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].plugins
         this.enterRoom();
       },
 
-      enterRoom(ev) {
+      async enterRoom(ev) {
         if (ev) {
           ev.preventDefault();
         }
 
         if (this.model.get('connection_status') !== _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_3__["default"].ROOMSTATUS.ENTERED) {
-          const handler = () => {
-            if (!u.isPersistableModel(this.model)) {
-              // Happens during tests, nothing to do if this
-              // is a hanging chatbox (i.e. not in the collection anymore).
-              return;
-            }
+          await this.model.getRoomFeatures();
 
-            this.populateAndJoin();
-
-            _converse.emit('chatRoomOpened', this);
-          };
+          if (!u.isPersistableModel(this.model)) {
+            // XXX: Happens during tests, nothing to do if this
+            // is a hanging chatbox (i.e. not in the collection anymore).
+            return;
+          }
 
-          this.model.getRoomFeatures().then(handler, handler);
+          this.populateAndJoin();
         } else {
           this.fetchMessages();
-
-          _converse.emit('chatRoomOpened', this);
         }
+
+        _converse.emit('chatRoomOpened', this);
       },
 
       render() {

+ 8 - 11
src/converse-muc-views.js

@@ -512,23 +512,20 @@ converse.plugins.add('converse-muc-views', {
                 this.enterRoom();
             },
 
-            enterRoom (ev) {
+            async enterRoom (ev) {
                 if (ev) { ev.preventDefault(); }
                 if (this.model.get('connection_status') !==  converse.ROOMSTATUS.ENTERED) {
-                    const handler = () => {
-                        if (!u.isPersistableModel(this.model)) {
-                            // Happens during tests, nothing to do if this
-                            // is a hanging chatbox (i.e. not in the collection anymore).
-                            return;
-                        }
-                        this.populateAndJoin();
-                        _converse.emit('chatRoomOpened', this);
+                    await this.model.getRoomFeatures();
+                    if (!u.isPersistableModel(this.model)) {
+                        // XXX: Happens during tests, nothing to do if this
+                        // is a hanging chatbox (i.e. not in the collection anymore).
+                        return;
                     }
-                    this.model.getRoomFeatures().then(handler, handler);
+                    this.populateAndJoin();
                 } else {
                     this.fetchMessages();
-                    _converse.emit('chatRoomOpened', this);
                 }
+                _converse.emit('chatRoomOpened', this);
             },
 
             render () {