Explorar o código

Bugfix. Make sure `_devices_promise` is a Promise

JC Brand %!s(int64=6) %!d(string=hai) anos
pai
achega
affafc746c
Modificáronse 2 ficheiros con 32 adicións e 24 borrados
  1. 17 12
      dist/converse.js
  2. 15 12
      src/converse-omemo.js

+ 17 - 12
dist/converse.js

@@ -66192,21 +66192,26 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
 
       fetchDevices() {
         if (_.isUndefined(this._devices_promise)) {
-          const options = {
-            'success': c => this.onCachedDevicesFetched(c),
-            'error': e => _converse.log(e, Strophe.LogLevel.ERROR)
-          };
-          this._devices_promise = this.devices.fetch(options);
-        }
+          this._devices_promise = new Promise(resolve => {
+            this.devices.fetch({
+              'success': async collection => {
+                if (collection.length === 0) {
+                  const ids = await this.fetchDevicesFromServer();
+                  await this.publishCurrentDevice(ids);
+                }
 
-        return this._devices_promise;
-      },
+                resolve();
+              },
+              'error': e => {
+                _converse.log(e, Strophe.LogLevel.ERROR);
 
-      async onCachedDevicesFetched(collection) {
-        if (collection.length === 0) {
-          const ids = await this.fetchDevicesFromServer();
-          this.publishCurrentDevice(ids);
+                resolve();
+              }
+            });
+          });
         }
+
+        return this._devices_promise;
       },
 
       async publishCurrentDevice(device_ids) {

+ 15 - 12
src/converse-omemo.js

@@ -840,22 +840,25 @@ converse.plugins.add('converse-omemo', {
 
             fetchDevices () {
                 if (_.isUndefined(this._devices_promise)) {
-                    const options = {
-                        'success': c => this.onCachedDevicesFetched(c),
-                        'error': e => _converse.log(e, Strophe.LogLevel.ERROR)
-                    }
-                    this._devices_promise = this.devices.fetch(options);
+                    this._devices_promise = new Promise(resolve => {
+                        this.devices.fetch({
+                            'success': async collection => {
+                                if (collection.length === 0) {
+                                    const ids = await this.fetchDevicesFromServer()
+                                    await this.publishCurrentDevice(ids);
+                                }
+                                resolve();
+                            },
+                            'error': e => {
+                                _converse.log(e, Strophe.LogLevel.ERROR);
+                                resolve();
+                            }
+                        });
+                    });
                 }
                 return this._devices_promise;
             },
 
-            async onCachedDevicesFetched (collection) {
-                if (collection.length === 0) {
-                    const ids = await this.fetchDevicesFromServer()
-                    this.publishCurrentDevice(ids);
-                }
-            },
-
             async publishCurrentDevice (device_ids) {
                 if (this.get('jid') !== _converse.bare_jid) {
                     // We only publish for ourselves.