Commit affafc74 authored by JC Brand's avatar JC Brand

Bugfix. Make sure `_devices_promise` is a Promise

parent 1c38863b
...@@ -66192,21 +66192,26 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins ...@@ -66192,21 +66192,26 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
fetchDevices() { fetchDevices() {
if (_.isUndefined(this._devices_promise)) { if (_.isUndefined(this._devices_promise)) {
const options = { this._devices_promise = new Promise(resolve => {
'success': c => this.onCachedDevicesFetched(c), this.devices.fetch({
'error': e => _converse.log(e, Strophe.LogLevel.ERROR) 'success': async collection => {
}; if (collection.length === 0) {
this._devices_promise = this.devices.fetch(options); 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) { resolve();
if (collection.length === 0) {
const ids = await this.fetchDevicesFromServer();
this.publishCurrentDevice(ids);
} }
});
});
}
return this._devices_promise;
}, },
async publishCurrentDevice(device_ids) { async publishCurrentDevice(device_ids) {
...@@ -840,20 +840,23 @@ converse.plugins.add('converse-omemo', { ...@@ -840,20 +840,23 @@ converse.plugins.add('converse-omemo', {
fetchDevices () { fetchDevices () {
if (_.isUndefined(this._devices_promise)) { if (_.isUndefined(this._devices_promise)) {
const options = { this._devices_promise = new Promise(resolve => {
'success': c => this.onCachedDevicesFetched(c), this.devices.fetch({
'error': e => _converse.log(e, Strophe.LogLevel.ERROR) 'success': async collection => {
}
this._devices_promise = this.devices.fetch(options);
}
return this._devices_promise;
},
async onCachedDevicesFetched (collection) {
if (collection.length === 0) { if (collection.length === 0) {
const ids = await this.fetchDevicesFromServer() const ids = await this.fetchDevicesFromServer()
this.publishCurrentDevice(ids); await this.publishCurrentDevice(ids);
}
resolve();
},
'error': e => {
_converse.log(e, Strophe.LogLevel.ERROR);
resolve();
} }
});
});
}
return this._devices_promise;
}, },
async publishCurrentDevice (device_ids) { async publishCurrentDevice (device_ids) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment