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