Reformat and remove stale debugging

This commit is contained in:
2026-02-16 19:50:17 +00:00
parent 658ab10647
commit f3ced1bfd8
10 changed files with 122 additions and 105 deletions

View File

@@ -685,7 +685,7 @@ class WhatsAppClient(ClientBase):
payload = dict((command or {}).get("payload") or {})
if not command_id:
return
self.log.info(
self.log.debug(
"whatsapp runtime command start: id=%s action=%s",
command_id,
action,
@@ -718,7 +718,7 @@ class WhatsAppClient(ClientBase):
else int(time.time() * 1000),
},
)
self.log.info(
self.log.debug(
"whatsapp runtime command ok: id=%s action=%s",
command_id,
action,
@@ -800,7 +800,9 @@ class WhatsAppClient(ClientBase):
return
if action == "notify_xmpp_sent":
person_identifier_id = str(payload.get("person_identifier_id") or "").strip()
person_identifier_id = str(
payload.get("person_identifier_id") or ""
).strip()
text = str(payload.get("text") or "")
if not person_identifier_id:
transport.set_runtime_command_result(
@@ -811,7 +813,9 @@ class WhatsAppClient(ClientBase):
return
try:
identifier = await sync_to_async(
lambda: PersonIdentifier.objects.filter(id=person_identifier_id).select_related("user", "person").first()
lambda: PersonIdentifier.objects.filter(id=person_identifier_id)
.select_related("user", "person")
.first()
)()
if identifier is None:
transport.set_runtime_command_result(
@@ -1424,13 +1428,13 @@ class WhatsAppClient(ClientBase):
# Read contact-like rows directly from the session sqlite DB instead.
contacts, source, lid_map = await self._sync_contacts_from_sqlite()
if not contacts:
self.log.info("whatsapp contacts sync empty (%s)", source or "unknown")
self.log.debug("whatsapp contacts sync empty (%s)", source or "unknown")
self._publish_state(
last_event="contacts_sync_empty",
contacts_source=source or "unknown",
)
return
self.log.info(
self.log.debug(
"whatsapp contacts synced: count=%s source=%s",
len(contacts),
source or "unknown",
@@ -2600,7 +2604,11 @@ class WhatsAppClient(ClientBase):
)
if is_transient and attempt < 1:
# If runtime rejected string target, try to build protobuf JID for retry.
if jid_obj is None and self._build_jid is not None and "@" in jid_str:
if (
jid_obj is None
and self._build_jid is not None
and "@" in jid_str
):
local_part, server_part = jid_str.split("@", 1)
try:
maybe_retry_jid = self._build_jid(local_part, server_part)
@@ -2740,10 +2748,12 @@ class WhatsAppClient(ClientBase):
async def send_message_to_contact(self, contact_jid: str, text: str) -> bool:
"""Send a text message to a WhatsApp contact."""
try:
jid = build_jid(contact_jid.split("@")[0], contact_jid.split("@")[1])
jid = self._to_jid(contact_jid)
if not jid or self._client is None:
return False
# neonize.send_message() accepts either a Message protobuf or a plain string
# If passing a string, it auto-converts to Message(conversation=text)
response = self.client.send_message(jid, text)
response = self._client.send_message(jid, text)
return response is not None
except Exception as e:
self.log.error(f"Failed to send WhatsApp message: {e}")
@@ -2753,8 +2763,10 @@ class WhatsAppClient(ClientBase):
async def send_structured_message(self, contact_jid: str, message: Message) -> bool:
"""Send a structured Message protobuf to a WhatsApp contact."""
try:
jid = build_jid(contact_jid.split("@")[0], contact_jid.split("@")[1])
response = self.client.send_message(jid, message)
jid = self._to_jid(contact_jid)
if not jid or self._client is None:
return False
response = self._client.send_message(jid, message)
return response is not None
except Exception as e:
self.log.error(f"Failed to send structured WhatsApp message: {e}")