impromptu: Wait for the self-presence to configure and invite

MucTab.join doesn't allow us to wait until we are fully joined to a MUC,
causing races between the MUC creation and configuration, making it
impossible for invited users to join the MUC.

This adds a disposable event (discarded after first use) that listens on
the self-presence on the generated JID.

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2021-12-24 23:10:03 +01:00
parent 49734de674
commit 07f56779a8
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -1017,18 +1017,27 @@ class Core:
return None
self.open_new_room(room, nick).join()
iq = self._impromptu_room_form(room)
try:
await iq.send()
except (IqError, IqTimeout):
self.information('Failed to configure impromptu room.', 'Info')
# TODO: destroy? leave room.
return None
self.information('Room %s created' % room, 'Info')
async def join_callback(_presence):
iq = self._impromptu_room_form(room)
try:
await iq.send()
except (IqError, IqTimeout):
self.information('Failed to configure impromptu room.', 'Info')
# TODO: destroy? leave room.
return None
for jid in jids:
await self.invite(jid, room, force_mediated=True)
self.information('Room %s created' % room, 'Info')
for jid in jids:
await self.invite(jid, room, force_mediated=True)
# TODO: Use xep_0045's async join_muc_wait somehow instead?
self.xmpp.add_event_handler(
'muc::%s::self-presence' % room.bare,
join_callback,
disposable=True,
)
####################### Tab logic-related things ##############################