plugin XEP-0045: Use disco as fallback for is_room:
If a room was not joined (e.g., due to failure), `is_room` was wrongly returning `False`. Disco identity is now used as fallback to detect correctly is an entity is a room or not. This changes makes `is_room` async, and by extension `get_bare_or_full` too.
This commit is contained in:
parent
e5781641f3
commit
dc9e3e98d5
1 changed files with 21 additions and 24 deletions
|
|
@ -396,20 +396,27 @@ class XEP_0045:
|
|||
return False
|
||||
return True
|
||||
|
||||
def is_room(self, client: SatXMPPEntity, entity_jid: jid.JID) -> bool:
|
||||
"""Check if a JID is a joined MUC.
|
||||
async def is_room(self, client: SatXMPPEntity, entity_jid: jid.JID) -> bool:
|
||||
"""Check if a JID is a joined MUC or a known MUC service.
|
||||
|
||||
@param client: The client instance.
|
||||
@param entity_jid: JID of the entity to check.
|
||||
@return: True if the JID is a joined MUC.
|
||||
@return: True if the JID is a joined MUC or a known MUC service.
|
||||
"""
|
||||
try:
|
||||
self.check_room_joined(client, entity_jid.userhostJID())
|
||||
except exceptions.NotFound:
|
||||
return False
|
||||
# It's not a joined room (yet?), we check disco as fallback.
|
||||
try:
|
||||
return await self.host.memory.disco.has_identity(
|
||||
client, "conference", "text", entity_jid.userhostJID()
|
||||
)
|
||||
except Exception:
|
||||
log.exception(f"Can't get identity of {entity_jid.full()}")
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_bare_or_full(self, client: SatXMPPEntity, peer_jid: jid.JID) -> jid.JID:
|
||||
async def get_bare_or_full(self, client: SatXMPPEntity, peer_jid: jid.JID) -> jid.JID:
|
||||
"""Use full JID if peer is an occupant of a room, bare JID else.
|
||||
|
||||
@param client: The client instance.
|
||||
|
|
@ -417,7 +424,7 @@ class XEP_0045:
|
|||
@return: Bare or full JID.
|
||||
"""
|
||||
if peer_jid.resource:
|
||||
if not self.is_room(client, peer_jid):
|
||||
if not await self.is_room(client, peer_jid):
|
||||
return peer_jid.userhostJID()
|
||||
return peer_jid
|
||||
|
||||
|
|
@ -917,19 +924,10 @@ class XEP_0045:
|
|||
|
||||
if room_jid in muc_client.joined_rooms:
|
||||
room = muc_client.joined_rooms[room_jid]
|
||||
log.info(
|
||||
f"{client.profile} is already in room {room_jid}",
|
||||
profile=client.profile,
|
||||
room_jid=room_jid.userhost(),
|
||||
)
|
||||
log.info(f"{client.profile} is already in room {room_jid.userhost()}")
|
||||
raise AlreadyJoined(room)
|
||||
|
||||
log.info(
|
||||
f"[{client.profile}] joining room {room_jid} as {nick}",
|
||||
profile=client.profile,
|
||||
room=room_jid.userhost(),
|
||||
nick=nick,
|
||||
)
|
||||
log.info(f"[{client.profile}] joining room {room_jid.userhost()} as {nick}")
|
||||
|
||||
password = options.get("password")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue