enhancement: Improve JID handling and logging in MUC plugin; update status code return type

This commit is contained in:
jinyu 2024-11-15 17:53:08 +08:00 committed by mathieui
parent df0ecfc142
commit f24a7679e5
3 changed files with 35 additions and 7 deletions

View File

@ -27,3 +27,9 @@ from slixmpp.clientxmpp import ClientXMPP
from slixmpp.componentxmpp import ComponentXMPP
from slixmpp.version import __version__, __version_info__
__all__ = [
'Message', 'Presence', 'Iq', 'JID', 'InvalidJID', 'ET', 'ElementBase',
'register_stanza_plugin', 'XMLStream', 'BaseXMPP', 'ClientXMPP', 'ComponentXMPP',
'__version__', '__version_info__'
]

View File

@ -650,13 +650,23 @@ class XEP_0045(BasePlugin):
:param room: Room to check.
:param jid: FULL JID to check.
"""
bare_match = False
for nick in self.rooms[room]:
entry = self.rooms[room][nick]
if not entry.get('jid'):
continue
if entry is not None and entry['jid'] == jid.full:
if entry['jid'] == jid.full:
return True
return False
elif JID(entry['jid']) == jid.bare:
bare_match = True
if bare_match:
logging.info(
"Could not retrieve full JID, falling back to bare JID for %s in %s",
jid, room
)
return bare_match
def get_nick(self, room: JID, jid: JID) -> Optional[str]:
"""Get the nickname of a specific JID in a room.
@ -664,13 +674,23 @@ class XEP_0045(BasePlugin):
:param room: Room to inspect.
:param jid: FULL JID whose nick to return.
"""
bare_match = None
for nick in self.rooms[room]:
entry = self.rooms[room][nick]
if not entry.get('jid'):
continue
if entry is not None and entry['jid'] == jid.full:
if entry['jid'] == jid.full:
return nick
return None
elif JID(entry['jid']) == jid.bare:
bare_match = nick
if bare_match:
logging.info(
"Could not retrieve full JID, falling back to bare JID for %s in %s",
jid, room
)
return bare_match
def get_joined_rooms(self) -> List[JID]:
"""Get the list of rooms we sent a join presence to

View File

@ -28,7 +28,7 @@ class MUCBase(ElementBase):
plugin_attrib = 'muc'
interfaces = {'affiliation', 'role', 'jid', 'nick', 'room', 'status_codes'}
def get_status_codes(self) -> Set[str]:
def get_status_codes(self) -> Set[int]:
status = self.xml.findall(f'{{{NS_USER}}}status')
return {int(status.attrib['code']) for status in status}
@ -275,7 +275,8 @@ class MUCUserItem(ElementBase):
jid = self.xml.attrib.get('jid', None)
if jid:
return JID(jid)
return jid
else:
return None
class MUCActor(ElementBase):
@ -288,7 +289,8 @@ class MUCActor(ElementBase):
jid = self.xml.attrib.get('jid', None)
if jid:
return JID(jid)
return jid
else:
return None
class MUCDestroy(ElementBase):