Fix join_muc_wait: end join only upon receiving the room subject
This commit is contained in:
parent
28fe68c7d3
commit
815b7d5af7
1 changed files with 24 additions and 13 deletions
|
@ -254,6 +254,7 @@ class XEP_0045(BasePlugin):
|
||||||
if msg['body'] or msg['thread']:
|
if msg['body'] or msg['thread']:
|
||||||
return
|
return
|
||||||
self.xmpp.event('groupchat_subject', msg)
|
self.xmpp.event('groupchat_subject', msg)
|
||||||
|
self.xmpp.event('muc::%s::groupchat_subject' % msg['from'].bare)
|
||||||
|
|
||||||
async def join_muc_wait(self, room: JID, nick: str, *,
|
async def join_muc_wait(self, room: JID, nick: str, *,
|
||||||
password: Optional[str] = None,
|
password: Optional[str] = None,
|
||||||
|
@ -262,7 +263,7 @@ class XEP_0045(BasePlugin):
|
||||||
seconds: Optional[int] = None,
|
seconds: Optional[int] = None,
|
||||||
since: Optional[datetime] = None,
|
since: Optional[datetime] = None,
|
||||||
presence_options: Optional[PresenceArgs] = None,
|
presence_options: Optional[PresenceArgs] = None,
|
||||||
timeout: Optional[int] = None) -> Presence:
|
timeout: Optional[int] = None) -> Tuple[Presence, Message]:
|
||||||
"""
|
"""
|
||||||
Try to join a MUC and block until we are joined or get an error.
|
Try to join a MUC and block until we are joined or get an error.
|
||||||
|
|
||||||
|
@ -282,7 +283,7 @@ class XEP_0045(BasePlugin):
|
||||||
presence error.
|
presence error.
|
||||||
:raises: An asyncio.TimeoutError if there is neither success nor
|
:raises: An asyncio.TimeoutError if there is neither success nor
|
||||||
presence error when the timeout is reached.
|
presence error when the timeout is reached.
|
||||||
:return: Our own presence
|
:return: Our own presence and the subject
|
||||||
"""
|
"""
|
||||||
if presence_options is None:
|
if presence_options is None:
|
||||||
presence_options = {}
|
presence_options = {}
|
||||||
|
@ -306,22 +307,32 @@ class XEP_0045(BasePlugin):
|
||||||
self.our_nicks[room] = nick
|
self.our_nicks[room] = nick
|
||||||
stanza.send()
|
stanza.send()
|
||||||
|
|
||||||
future: asyncio.Future = asyncio.Future()
|
presence_done: asyncio.Future = asyncio.Future()
|
||||||
context1 = self.xmpp.event_handler("muc::%s::self-presence" % room, future.set_result)
|
topic_received: asyncio.Future = asyncio.Future()
|
||||||
context2 = self.xmpp.event_handler("muc::%s::presence-error" % room, future.set_result)
|
context0 = self.xmpp.event_handler("muc::%s::groupchat_subject" % room, topic_received.set_result)
|
||||||
with context1, context2:
|
context1 = self.xmpp.event_handler("muc::%s::self-presence" % room, presence_done.set_result)
|
||||||
|
context2 = self.xmpp.event_handler("muc::%s::presence-error" % room, presence_done.set_result)
|
||||||
|
with context0:
|
||||||
|
with context1, context2:
|
||||||
|
done, pending = await asyncio.wait(
|
||||||
|
[presence_done],
|
||||||
|
timeout=timeout,
|
||||||
|
)
|
||||||
|
if pending:
|
||||||
|
raise asyncio.TimeoutError()
|
||||||
|
pres: Presence = presence_done.result()
|
||||||
|
if pres['type'] == 'error':
|
||||||
|
raise PresenceError(pres)
|
||||||
done, pending = await asyncio.wait(
|
done, pending = await asyncio.wait(
|
||||||
[future],
|
[topic_received],
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
if pending:
|
if pending:
|
||||||
raise asyncio.TimeoutError()
|
raise asyncio.TimeoutError()
|
||||||
pres = await future
|
subject: Message = topic_received.result()
|
||||||
if pres['type'] == 'error':
|
|
||||||
raise PresenceError(pres)
|
|
||||||
# update known nick in case it has changed
|
# update known nick in case it has changed
|
||||||
self.our_nicks[room] = pres['from'].resource
|
self.our_nicks[room] = pres['from'].resource
|
||||||
return pres
|
return (pres, subject)
|
||||||
|
|
||||||
def join_muc(self, room: JID, nick: str, maxhistory="0", password='',
|
def join_muc(self, room: JID, nick: str, maxhistory="0", password='',
|
||||||
pstatus='', pshow='', pfrom='') -> asyncio.Future:
|
pstatus='', pshow='', pfrom='') -> asyncio.Future:
|
||||||
|
|
Loading…
Reference in a new issue