Use async/await

This commit is contained in:
JC Brand 2018-12-17 14:36:55 +01:00
parent 93bfa3bbbe
commit 9c812157ee
3 changed files with 20 additions and 23 deletions

15
dist/converse.js vendored
View File

@ -62996,14 +62996,14 @@ function cleanup() {
_converse.connection.reset();
_converse.tearDown();
_converse.stopListening();
_converse.tearDown();
_converse.off();
delete _converse.config;
initClientConfig();
_converse.off();
}
_converse.initialize = function (settings, callback) {
@ -64575,12 +64575,15 @@ _converse_core__WEBPACK_IMPORTED_MODULE_0__["default"].plugins.add('converse-dis
}
},
queryInfo() {
_converse.api.disco.info(this.get('jid'), null).then(stanza => this.onInfo(stanza)).catch(iq => {
async queryInfo() {
try {
const stanza = await _converse.api.disco.info(this.get('jid'), null);
this.onInfo(stanza);
} catch (iq) {
this.waitUntilFeaturesDiscovered.resolve(this);
_converse.log(iq, Strophe.LogLevel.ERROR);
});
}
},
onDiscoItems(stanza) {

View File

@ -1626,26 +1626,19 @@
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) {
let sent_IQ, IQ_id;
const IQ_stanzas = _converse.connection.IQ_stanzas;
const sendIQ = _converse.connection.sendIQ;
const room_jid = 'lounge@localhost';
spyOn(_converse.connection, 'sendIQ').and.callFake(function (iq, callback, errback) {
if (iq.nodeTree.getAttribute('to') === 'lounge@localhost') {
sent_IQ = iq;
IQ_id = sendIQ.bind(this)(iq, callback, errback);
} else {
sendIQ.bind(this)(iq, callback, errback);
}
});
await test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
let stanza = await test_utils.waitUntil(() => _.get(_.filter(
IQ_stanzas,
iq => iq.nodeTree.querySelector(
`iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
)).pop(), 'nodeTree')
);
// We pretend this is a new room, so no disco info is returned.
const features_stanza = $iq({
from: 'lounge@localhost',
@ -1693,7 +1686,7 @@
*/
stanza = $iq({
'type': 'result',
'id': IQ_id,
'id': node.nodeTree.getAttribute('id'),
'from': view.model.get('jid'),
'to': _converse.connection.jid
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info', 'node': 'x-roomuser-item'})

View File

@ -134,13 +134,14 @@ converse.plugins.add('converse-disco', {
}
},
queryInfo () {
_converse.api.disco.info(this.get('jid'), null)
.then(stanza => this.onInfo(stanza))
.catch(iq => {
this.waitUntilFeaturesDiscovered.resolve(this);
_converse.log(iq, Strophe.LogLevel.ERROR);
});
async queryInfo () {
try {
const stanza = await _converse.api.disco.info(this.get('jid'), null);
this.onInfo(stanza);
} catch(iq) {
this.waitUntilFeaturesDiscovered.resolve(this);
_converse.log(iq, Strophe.LogLevel.ERROR);
}
},
onDiscoItems (stanza) {