Commit 5f5de90f authored by JC Brand's avatar JC Brand

MUC: Don't set a default nick

We first want to check whether the user has registered a nick with the
MUC, and if so, that will be set as the nick.
parent c8f0fd2a
......@@ -160,16 +160,13 @@
const room_jid = 'coven@chat.shakespeare.lit';
test_utils.openControlBox();
await _converse.api.rooms.open(room_jid, {'nick': 'some1'});
const last_stanza = await u.waitUntil(() => _.filter(
IQ_stanzas,
iq => iq.querySelector(
`iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`
)).pop());
const view = _converse.chatboxviews.get(room_jid);
const IQ_id = last_stanza.getAttribute('id');
const selector = `iq[to="${room_jid}"] query[xmlns="http://jabber.org/protocol/disco#info"]`;
const features_query = await u.waitUntil(() => IQ_stanzas.filter(iq => iq.querySelector(selector)).pop());
const features_stanza = $iq({
'from': 'coven@chat.shakespeare.lit',
'id': IQ_id,
'id': features_query.getAttribute('id'),
'to': 'romeo@montague.lit/desktop',
'type': 'result'
})
......
......@@ -385,7 +385,6 @@ converse.plugins.add('converse-muc', {
'hidden': ['mobile', 'fullscreen'].includes(_converse.view_mode),
'message_type': 'groupchat',
'name': '',
'nick': _converse.getDefaultMUCNickname(),
'num_unread': 0,
'roomconfig': {},
'time_opened': this.get('time_opened') || (new Date()).getTime(),
......@@ -1194,10 +1193,7 @@ converse.plugins.add('converse-muc', {
* @returns { Promise<string> } A promise which resolves with the reserved nick or null
*/
async getReservedNick () {
let iq;
try {
iq = await _converse.api.sendIQ(
$iq({
const stanza = $iq({
'to': this.get('jid'),
'from': _converse.connection.jid,
'type': "get"
......@@ -1205,23 +1201,18 @@ converse.plugins.add('converse-muc', {
'xmlns': Strophe.NS.DISCO_INFO,
'node': 'x-roomuser-item'
})
);
} catch (e) {
if (_.isElement(e)) {
// IQ stanza of type 'error'
return;
} else {
throw e;
const result = await _converse.api.sendIQ(stanza, null, true);
if (u.isErrorObject(result)) {
throw result;
}
}
const identity_el = iq.querySelector('query[node="x-roomuser-item"] identity');
const identity_el = result.querySelector('query[node="x-roomuser-item"] identity');
return identity_el ? identity_el.getAttribute('name') : null;
},
async registerNickname () {
// See https://xmpp.org/extensions/xep-0045.html#register
const nick = this.get('nick'),
jid = this.get('jid');
const nick = this.get('nick');
const jid = this.get('jid');
let iq, err_msg;
try {
iq = await _converse.api.sendIQ(
......
......@@ -192,10 +192,9 @@
utils.waitForReservedNick = async function (_converse, muc_jid, nick) {
const view = _converse.chatboxviews.get(muc_jid);
const stanzas = _converse.connection.IQ_stanzas;
const iq = await u.waitUntil(() => _.filter(
stanzas,
s => sizzle(`iq[to="${muc_jid.toLowerCase()}"] query[node="x-roomuser-item"]`, s).length
).pop());
const selector = `iq[to="${muc_jid.toLowerCase()}"] query[node="x-roomuser-item"]`;
const iq = await u.waitUntil(() => stanzas.filter(s => sizzle(selector, s).length).pop());
// We remove the stanza, otherwise we might get stale stanzas returned in our filter above.
stanzas.splice(stanzas.indexOf(iq), 1)
......
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