Fix issues with multiplatform conversation displays

This commit is contained in:
2026-02-16 11:42:53 +00:00
parent cf651a3bd4
commit a70faa3576
10 changed files with 489 additions and 78 deletions

View File

@@ -2211,16 +2211,18 @@ class WhatsAppClient(ClientBase):
raw = str(recipient or "").strip()
if not raw:
return ""
if "@" in raw:
return raw
digits = re.sub(r"[^0-9]", "", raw)
if digits:
# Prefer direct JID formatting for phone numbers; Neonize build_jid
# can trigger a usync lookup path that intermittently times out.
return f"{digits}@s.whatsapp.net"
if self._build_jid is not None:
try:
return self._build_jid(raw)
except Exception:
pass
if "@" in raw:
return raw
digits = re.sub(r"[^0-9]", "", raw)
if digits:
return f"{digits}@s.whatsapp.net"
return raw
def _blob_key_to_compose_url(self, blob_key):
@@ -2275,6 +2277,23 @@ class WhatsAppClient(ClientBase):
jid = self._to_jid(recipient)
if not jid:
return False
if not self._connected and hasattr(self._client, "connect"):
try:
await self._maybe_await(self._client.connect())
self._connected = True
self._publish_state(
connected=True,
last_event="send_reconnect_ok",
warning="",
last_error="",
)
except Exception as exc:
self._publish_state(
connected=False,
last_event="send_reconnect_failed",
last_error=str(exc),
warning=f"WhatsApp reconnect before send failed: {exc}",
)
sent_any = False
sent_ts = 0
@@ -2318,16 +2337,50 @@ class WhatsAppClient(ClientBase):
self.log.warning("whatsapp attachment send failed: %s", exc)
if text:
try:
response = await self._maybe_await(self._client.send_message(jid, text))
sent_any = True
except TypeError:
response = await self._maybe_await(
self._client.send_message(jid, message=text)
)
sent_any = True
except Exception as exc:
self.log.warning("whatsapp text send failed: %s", exc)
response = None
last_error = None
for attempt in range(3):
try:
response = await self._maybe_await(self._client.send_message(jid, text))
sent_any = True
last_error = None
break
except TypeError:
try:
response = await self._maybe_await(
self._client.send_message(jid, message=text)
)
sent_any = True
last_error = None
break
except Exception as exc:
last_error = exc
except Exception as exc:
last_error = exc
error_text = str(last_error or "").lower()
is_transient = "usync query" in error_text or "timed out" in error_text
if is_transient and attempt < 2:
if hasattr(self._client, "connect"):
try:
await self._maybe_await(self._client.connect())
self._connected = True
self._publish_state(
connected=True,
last_event="send_retry_reconnect_ok",
warning="",
)
except Exception as reconnect_exc:
self._publish_state(
connected=False,
last_event="send_retry_reconnect_failed",
last_error=str(reconnect_exc),
)
await asyncio.sleep(0.8 * (attempt + 1))
continue
break
if last_error is not None and not sent_any:
self.log.warning("whatsapp text send failed: %s", last_error)
return False
sent_ts = max(
sent_ts,