summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime “pep” Buquet <pep@bouah.net>2022-03-01 00:34:18 +0100
committermathieui <mathieui@mathieui.net>2022-03-01 22:38:03 +0100
commitee82c6717dcbc50ef5bc288d2ffb307339006b2f (patch)
tree9be1526f5dff00738d8f2c6349c5652d14833463
parent1e6073e0eccb6ee0c261801fc8afcb9a80f80fad (diff)
downloadpoezio-ee82c6717dcbc50ef5bc288d2ffb307339006b2f.tar.gz
poezio-ee82c6717dcbc50ef5bc288d2ffb307339006b2f.tar.bz2
poezio-ee82c6717dcbc50ef5bc288d2ffb307339006b2f.tar.xz
poezio-ee82c6717dcbc50ef5bc288d2ffb307339006b2f.zip
impromptu: Ensure a room is empty before joining
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r--poezio/core/core.py42
1 files changed, 33 insertions, 9 deletions
diff --git a/poezio/core/core.py b/poezio/core/core.py
index a1fdde0d..05008e02 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -1004,19 +1004,43 @@ class Core:
)
return
- nick = self.own_nick
- localpart = utils.pronounceable()
- room_str = '{!s}@{!s}'.format(localpart, default_muc)
- try:
- room = JID(room_str)
- except InvalidJID:
+ # Retries generating a name until we find a non-existing room.
+ # Abort otherwise.
+ retries = 3
+ while retries > 0:
+ localpart = utils.pronounceable()
+ 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(
- 'The generated XMPP address is invalid: {!s}'.format(room_str),
- 'Error'
+ 'Couldn\'t generate a room name that isn\'t already used.',
+ 'Error',
)
return None
- self.open_new_room(room, nick).join()
+ self.open_new_room(room, self.own_nick).join()
async def join_callback(_presence):
iq = self._impromptu_room_form(room)