Use async/await

This commit is contained in:
JC Brand 2018-12-21 03:55:45 +01:00
parent 6f10f95d77
commit a3830e9a7a
2 changed files with 32 additions and 31 deletions

33
dist/converse.js vendored
View File

@ -57078,23 +57078,24 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
});
function fetchDeviceLists() {
return new Promise((resolve, reject) => _converse.devicelists.fetch({
'success': resolve
return new Promise((success, error) => _converse.devicelists.fetch({
success,
error
}));
}
function fetchOwnDevices() {
return fetchDeviceLists().then(() => {
let own_devicelist = _converse.devicelists.get(_converse.bare_jid);
async function fetchOwnDevices() {
await fetchDeviceLists();
if (_.isNil(own_devicelist)) {
own_devicelist = _converse.devicelists.create({
'jid': _converse.bare_jid
});
}
let own_devicelist = _converse.devicelists.get(_converse.bare_jid);
return own_devicelist.fetchDevices();
});
if (_.isNil(own_devicelist)) {
own_devicelist = _converse.devicelists.create({
'jid': _converse.bare_jid
});
}
return own_devicelist.fetchDevices();
}
function updateBundleFromStanza(stanza) {
@ -57191,7 +57192,7 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
return _converse.omemo_store.fetchSession();
}
function initOMEMO() {
async function initOMEMO() {
if (!_converse.config.get('trusted')) {
return;
}
@ -57202,7 +57203,11 @@ _converse_headless_converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins
id = `converse.devicelists-${_converse.bare_jid}`;
_converse.devicelists.browserStorage = new Backbone.BrowserStorage[storage](id);
fetchOwnDevices().then(() => restoreOMEMOSession()).then(() => _converse.omemo_store.publishBundle()).then(() => _converse.emit('OMEMOInitialized')).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
await fetchOwnDevices();
await restoreOMEMOSession();
await _converse.omemo_store.publishBundle();
_converse.emit('OMEMOInitialized');
}
async function onOccupantAdded(chatroom, occupant) {

View File

@ -1028,19 +1028,16 @@ converse.plugins.add('converse-omemo', {
function fetchDeviceLists () {
return new Promise((resolve, reject) => _converse.devicelists.fetch({
'success': resolve
}));
return new Promise((success, error) => _converse.devicelists.fetch({success, error}));
}
function fetchOwnDevices () {
return fetchDeviceLists().then(() => {
let own_devicelist = _converse.devicelists.get(_converse.bare_jid);
if (_.isNil(own_devicelist)) {
own_devicelist = _converse.devicelists.create({'jid': _converse.bare_jid});
}
return own_devicelist.fetchDevices();
});
async function fetchOwnDevices () {
await fetchDeviceLists();
let own_devicelist = _converse.devicelists.get(_converse.bare_jid);
if (_.isNil(own_devicelist)) {
own_devicelist = _converse.devicelists.create({'jid': _converse.bare_jid});
}
return own_devicelist.fetchDevices();
}
function updateBundleFromStanza (stanza) {
@ -1115,7 +1112,7 @@ converse.plugins.add('converse-omemo', {
return _converse.omemo_store.fetchSession();
}
function initOMEMO () {
async function initOMEMO () {
if (!_converse.config.get('trusted')) {
return;
}
@ -1124,11 +1121,10 @@ converse.plugins.add('converse-omemo', {
id = `converse.devicelists-${_converse.bare_jid}`;
_converse.devicelists.browserStorage = new Backbone.BrowserStorage[storage](id);
fetchOwnDevices()
.then(() => restoreOMEMOSession())
.then(() => _converse.omemo_store.publishBundle())
.then(() => _converse.emit('OMEMOInitialized'))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
await fetchOwnDevices();
await restoreOMEMOSession();
await _converse.omemo_store.publishBundle();
_converse.emit('OMEMOInitialized');
}
async function onOccupantAdded (chatroom, occupant) {