impromptu: Ensure a room is empty before joining
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
1e6073e0ec
commit
ee82c6717d
1 changed files with 33 additions and 9 deletions
|
@ -1004,19 +1004,43 @@ class Core:
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
nick = self.own_nick
|
# Retries generating a name until we find a non-existing room.
|
||||||
localpart = utils.pronounceable()
|
# Abort otherwise.
|
||||||
room_str = '{!s}@{!s}'.format(localpart, default_muc)
|
retries = 3
|
||||||
try:
|
while retries > 0:
|
||||||
room = JID(room_str)
|
localpart = utils.pronounceable()
|
||||||
except InvalidJID:
|
room_str = '{!s}@{!s}'.format(localpart, default_muc
|
||||||
|
try:
|
||||||
|
room = JID(room_str)
|
||||||
|
except InvalidJID:
|
||||||
|
self.information(
|
||||||
|
'The generated XMPP address is invalid: {!s}'.format(room_str),
|
||||||
|
'Error'
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
iq = await self.xmpp['xep_0030'].get_info(
|
||||||
|
jid=room,
|
||||||
|
cached=False,
|
||||||
|
)
|
||||||
|
except IqTimeout:
|
||||||
|
pass
|
||||||
|
except IqError as exn:
|
||||||
|
if exn.etype == 'cancel' and exn.condition == 'item-not-found':
|
||||||
|
log.debug('Found empty room for /impromptu')
|
||||||
|
break
|
||||||
|
|
||||||
|
retries = retries - 1
|
||||||
|
|
||||||
|
if retries == 0:
|
||||||
self.information(
|
self.information(
|
||||||
'The generated XMPP address is invalid: {!s}'.format(room_str),
|
'Couldn\'t generate a room name that isn\'t already used.',
|
||||||
'Error'
|
'Error',
|
||||||
)
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
self.open_new_room(room, nick).join()
|
self.open_new_room(room, self.own_nick).join()
|
||||||
|
|
||||||
async def join_callback(_presence):
|
async def join_callback(_presence):
|
||||||
iq = self._impromptu_room_form(room)
|
iq = self._impromptu_room_form(room)
|
||||||
|
|
Loading…
Reference in a new issue