Fix slixmpp 1.13 compatibility and empty capabilities handling
- Replace process(forever=True) with asyncio event loop in _SlixClient.start() - Make send_xmpp_message() thread-safe via loop.call_soon_threadsafe() - Remove wait=True from join_muc() (no longer supported in slixmpp 1.13) - Silence empty retained MQTT capability messages in CapabilitiesRegistry Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,8 @@ class CapabilitiesRegistry:
|
||||
logger.debug(f"[Registry] Capacités mises à jour pour {caps.agent_id}")
|
||||
|
||||
def update_from_json(self, data: str | bytes) -> Optional[AgentCapabilities]:
|
||||
if not data or (isinstance(data, (str, bytes)) and not data.strip()):
|
||||
return None # Empty retained message — ignore silently
|
||||
try:
|
||||
caps = AgentCapabilities.from_json(data)
|
||||
self.update(caps)
|
||||
|
||||
@@ -187,8 +187,12 @@ class _SlixClient(ClientXMPP):
|
||||
logger.warning(f"[XMPP] OMEMO non disponible : {e}")
|
||||
|
||||
def start(self):
|
||||
import asyncio
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
self.loop = loop
|
||||
self.connect()
|
||||
self.process(forever=True)
|
||||
loop.run_forever()
|
||||
|
||||
async def _on_session_start(self, event):
|
||||
self.send_presence()
|
||||
@@ -197,7 +201,6 @@ class _SlixClient(ClientXMPP):
|
||||
self.plugin["xep_0045"].join_muc(
|
||||
room=self._muc_room,
|
||||
nick=self._muc_nick,
|
||||
wait=True,
|
||||
)
|
||||
if self._on_connected_cb:
|
||||
self._on_connected_cb()
|
||||
@@ -217,5 +220,10 @@ class _SlixClient(ClientXMPP):
|
||||
self._on_message_cb(str(msg["from"]), body, is_muc=True)
|
||||
|
||||
def send_xmpp_message(self, to: str, body: str, is_muc: bool = False):
|
||||
import functools
|
||||
msg_type = "groupchat" if is_muc else "chat"
|
||||
self.send_message(mto=to, mbody=body, mtype=msg_type)
|
||||
fn = functools.partial(self.send_message, mto=to, mbody=body, mtype=msg_type)
|
||||
if hasattr(self, 'loop') and self.loop and self.loop.is_running():
|
||||
self.loop.call_soon_threadsafe(fn)
|
||||
else:
|
||||
fn()
|
||||
|
||||
Reference in New Issue
Block a user