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

View File

@ -1626,26 +1626,19 @@
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
async function (done, _converse) { async function (done, _converse) {
let sent_IQ, IQ_id;
const IQ_stanzas = _converse.connection.IQ_stanzas; const IQ_stanzas = _converse.connection.IQ_stanzas;
const sendIQ = _converse.connection.sendIQ; const sendIQ = _converse.connection.sendIQ;
const room_jid = 'lounge@localhost'; 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'); await test_utils.openChatRoom(_converse, 'lounge', 'localhost', 'dummy');
let stanza = await test_utils.waitUntil(() => _.get(_.filter( let stanza = await test_utils.waitUntil(() => _.get(_.filter(
IQ_stanzas, IQ_stanzas,
iq => iq.nodeTree.querySelector( iq => iq.nodeTree.querySelector(
`iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]` `iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
)).pop(), 'nodeTree') )).pop(), 'nodeTree')
); );
// We pretend this is a new room, so no disco info is returned. // We pretend this is a new room, so no disco info is returned.
const features_stanza = $iq({ const features_stanza = $iq({
from: 'lounge@localhost', from: 'lounge@localhost',
@ -1693,7 +1686,7 @@
*/ */
stanza = $iq({ stanza = $iq({
'type': 'result', 'type': 'result',
'id': IQ_id, 'id': node.nodeTree.getAttribute('id'),
'from': view.model.get('jid'), 'from': view.model.get('jid'),
'to': _converse.connection.jid 'to': _converse.connection.jid
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info', 'node': 'x-roomuser-item'}) }).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 () { async queryInfo () {
_converse.api.disco.info(this.get('jid'), null) try {
.then(stanza => this.onInfo(stanza)) const stanza = await _converse.api.disco.info(this.get('jid'), null);
.catch(iq => { this.onInfo(stanza);
this.waitUntilFeaturesDiscovered.resolve(this); } catch(iq) {
_converse.log(iq, Strophe.LogLevel.ERROR); this.waitUntilFeaturesDiscovered.resolve(this);
}); _converse.log(iq, Strophe.LogLevel.ERROR);
}
}, },
onDiscoItems (stanza) { onDiscoItems (stanza) {