Commit 2d511a5e authored by JC Brand's avatar JC Brand

Make `openAndEnterChatRoom` and async function

parent c9546109
......@@ -116,19 +116,17 @@
return _converse.api.rooms.open(`${room}@${server}`);
};
utils.openAndEnterChatRoom = function (_converse, room, server, nick) {
let view;
utils.openAndEnterChatRoom = async function (_converse, room, server, nick) {
const room_jid = `${room}@${server}`.toLowerCase();
const stanzas = _converse.connection.IQ_stanzas;
return _converse.api.rooms.open(room_jid).then(() => {
view = _converse.chatboxviews.get(room_jid);
return utils.waitUntil(() => _.get(_.filter(
await _converse.api.rooms.open(room_jid);
const view = _converse.chatboxviews.get(room_jid);
let stanza = await utils.waitUntil(() => _.get(_.filter(
stanzas,
iq => iq.nodeTree.querySelector(
`iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
)).pop(), 'nodeTree'));
}).then(stanza => {
const features_stanza = $iq({
'from': room_jid,
'id': stanza.getAttribute('id'),
......@@ -156,18 +154,17 @@
.c('field', {'type':'text-single', 'var':'muc#roominfo_occupants', 'label':'Number of occupants'})
.c('value').t(0);
_converse.connection._dataRecv(utils.createRequest(features_stanza));
return utils.waitUntil(() => _.filter(
const iq = await utils.waitUntil(() => _.filter(
stanzas,
s => sizzle(`iq[to="${room_jid}"] query[node="x-roomuser-item"]`, s.nodeTree).length
).pop()
);
}).then(iq => {
).pop());
// We remove the stanza, otherwise we might get stale stanzas returned in our filter above.
stanzas.splice(stanzas.indexOf(iq), 1)
// The XMPP server returns the reserved nick for this user.
const IQ_id = iq.nodeTree.getAttribute('id');
const stanza = $iq({
stanza = $iq({
'type': 'result',
'id': IQ_id,
'from': view.model.get('jid'),
......@@ -175,8 +172,8 @@
}).c('query', {'xmlns': 'http://jabber.org/protocol/disco#info', 'node': 'x-roomuser-item'})
.c('identity', {'category': 'conference', 'name': nick, 'type': 'text'});
_converse.connection._dataRecv(utils.createRequest(stanza));
return utils.waitUntil(() => view.model.get('nick'));
}).then(() => {
await utils.waitUntil(() => view.model.get('nick'));
// The user has just entered the room (because join was called)
// and receives their own presence from the server.
// See example 24: http://xmpp.org/extensions/xep-0045.html#enter-pres
......@@ -192,11 +189,7 @@
}).up()
.c('status').attrs({code:'110'});
_converse.connection._dataRecv(utils.createRequest(presence));
return utils.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.ENTERED));
}).catch(e => {
console.error(e);
throw e;
});
await utils.waitUntil(() => (view.model.get('connection_status') === converse.ROOMSTATUS.ENTERED));
};
utils.clearBrowserStorage = function () {
......
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