Use async/await
This commit is contained in:
parent
267d91a4f3
commit
c9b540289c
1429
spec/chatroom.js
1429
spec/chatroom.js
File diff suppressed because it is too large
Load Diff
|
@ -15,34 +15,30 @@
|
||||||
}
|
}
|
||||||
utils.waitUntil = waitUntilPromise.default;
|
utils.waitUntil = waitUntilPromise.default;
|
||||||
|
|
||||||
utils.waitUntilDiscoConfirmed = function (_converse, entity_jid, identities, features, items, type) {
|
utils.waitUntilDiscoConfirmed = async function (_converse, entity_jid, identities, features, items, type='info') {
|
||||||
if (_.isNil(type)) {
|
const iq = await utils.waitUntil(() => {
|
||||||
type = 'info';
|
|
||||||
}
|
|
||||||
return utils.waitUntil(() => {
|
|
||||||
return _.filter(
|
return _.filter(
|
||||||
_converse.connection.IQ_stanzas,
|
_converse.connection.IQ_stanzas,
|
||||||
(iq) => sizzle(`iq[to="${entity_jid}"] query[xmlns="http://jabber.org/protocol/disco#${type}"]`, iq.nodeTree).length
|
(iq) => sizzle(`iq[to="${entity_jid}"] query[xmlns="http://jabber.org/protocol/disco#${type}"]`, iq.nodeTree).length
|
||||||
).pop();
|
).pop();
|
||||||
}, 300).then(iq => {
|
}, 300);
|
||||||
const stanza = $iq({
|
const stanza = $iq({
|
||||||
'type': 'result',
|
'type': 'result',
|
||||||
'from': entity_jid,
|
'from': entity_jid,
|
||||||
'to': 'dummy@localhost/resource',
|
'to': 'dummy@localhost/resource',
|
||||||
'id': iq.nodeTree.getAttribute('id'),
|
'id': iq.nodeTree.getAttribute('id'),
|
||||||
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#'+type});
|
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#'+type});
|
||||||
|
|
||||||
_.forEach(identities, function (identity) {
|
_.forEach(identities, function (identity) {
|
||||||
stanza.c('identity', {'category': identity.category, 'type': identity.type}).up()
|
stanza.c('identity', {'category': identity.category, 'type': identity.type}).up()
|
||||||
});
|
});
|
||||||
_.forEach(features, function (feature) {
|
_.forEach(features, function (feature) {
|
||||||
stanza.c('feature', {'var': feature}).up();
|
stanza.c('feature', {'var': feature}).up();
|
||||||
});
|
});
|
||||||
_.forEach(items, function (item) {
|
_.forEach(items, function (item) {
|
||||||
stanza.c('item', {'jid': item}).up();
|
stanza.c('item', {'jid': item}).up();
|
||||||
});
|
});
|
||||||
_converse.connection._dataRecv(utils.createRequest(stanza));
|
_converse.connection._dataRecv(utils.createRequest(stanza));
|
||||||
}).catch(_.partial(console.error, _));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.createRequest = function (iq) {
|
utils.createRequest = function (iq) {
|
||||||
|
@ -123,7 +119,7 @@
|
||||||
utils.openAndEnterChatRoom = function (_converse, room, server, nick) {
|
utils.openAndEnterChatRoom = function (_converse, room, server, nick) {
|
||||||
let view;
|
let view;
|
||||||
const room_jid = `${room}@${server}`.toLowerCase();
|
const room_jid = `${room}@${server}`.toLowerCase();
|
||||||
const stanzas = _converse.connection.IQ_stanzas;
|
const stanzas = _converse.connection.IQ_stanzas;
|
||||||
|
|
||||||
return _converse.api.rooms.open(room_jid).then(() => {
|
return _converse.api.rooms.open(room_jid).then(() => {
|
||||||
view = _converse.chatboxviews.get(room_jid);
|
view = _converse.chatboxviews.get(room_jid);
|
||||||
|
@ -175,7 +171,7 @@
|
||||||
'type': 'result',
|
'type': 'result',
|
||||||
'id': IQ_id,
|
'id': IQ_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'})
|
||||||
.c('identity', {'category': 'conference', 'name': nick, 'type': 'text'});
|
.c('identity', {'category': 'conference', 'name': nick, 'type': 'text'});
|
||||||
_converse.connection._dataRecv(utils.createRequest(stanza));
|
_converse.connection._dataRecv(utils.createRequest(stanza));
|
||||||
|
@ -256,7 +252,7 @@
|
||||||
converse.roster.create({
|
converse.roster.create({
|
||||||
'ask': ask,
|
'ask': ask,
|
||||||
'fullname': names[i],
|
'fullname': names[i],
|
||||||
'jid': jid,
|
'jid': jid,
|
||||||
'requesting': requesting,
|
'requesting': requesting,
|
||||||
'subscription': subscription
|
'subscription': subscription
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user