Reregister nick when changing it in a members-only MUC

This commit is contained in:
JC Brand 2021-10-30 20:20:42 +02:00
parent 6177afd5b1
commit 90d93b364a
2 changed files with 24 additions and 8 deletions

View File

@ -1403,6 +1403,29 @@ const ChatRoomMixin = {
return this.occupants.findWhere({ 'jid': _converse.bare_jid });
},
async setNickname (nick) {
this.set({ nick });
if (this.features.get('membersonly')) {
try {
await this.registerNickname();
} catch (e) {
const { __ } = _converse;
log.error(e);
const message = __("Error: couldn't register new nickname in members only room");
this.createMessage({ message, 'type': 'error' });
return;
}
}
const jid = Strophe.getBareJidFromJid(this.get('jid'));
api.send(
$pres({
from: _converse.connection.jid,
to: `${jid}/${nick}`,
id: u.getUniqueId()
}).tree()
)
},
/**
* Send an IQ stanza to modify an occupant's role
* @private

View File

@ -364,14 +364,7 @@ export function parseMessageForMUCCommands (muc, text) {
const message = __('Your nickname is "%1$s"', muc.get('nick'));
muc.createMessage({ message, 'type': 'error' });
} else {
const jid = Strophe.getBareJidFromJid(muc.get('jid'));
api.send(
$pres({
from: _converse.connection.jid,
to: `${jid}/${args}`,
id: u.getUniqueId()
}).tree()
);
muc.setNickname(args);
}
break;
}