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

@@ -2758,7 +2758,9 @@ class ComposeCommandResult(LoginRequiredMixin, View):
request,
"partials/compose-send-status.html",
{
"notice_message": str(timeout_result.get("error") or "Send failed."),
"notice_message": str(
timeout_result.get("error") or "Send failed."
),
"notice_level": "danger",
},
)
@@ -3323,12 +3325,12 @@ class ComposeSend(LoginRequiredMixin, View):
log_prefix = (
f"[ComposeSend] service={base['service']} identifier={base['identifier']}"
)
logger.info(f"{log_prefix} text_len={len(text)} attempting send")
logger.debug(f"{log_prefix} text_len={len(text)} attempting send")
# If runtime is out-of-process, enqueue command and return immediately (non-blocking).
# Expose command id for cancellation so the client can cancel or poll later.
runtime_client = transport.get_runtime_client(base["service"]) or None
logger.info(
logger.debug(
f"{log_prefix} runtime_client={type(runtime_client).__name__ if runtime_client else 'None (queued)'}"
)
ts = None
@@ -3338,7 +3340,9 @@ class ComposeSend(LoginRequiredMixin, View):
runtime_state = transport.get_runtime_state("whatsapp")
last_seen = int(runtime_state.get("runtime_seen_at") or 0)
is_connected = bool(runtime_state.get("connected"))
pair_status = str(runtime_state.get("pair_status") or "").strip().lower()
pair_status = (
str(runtime_state.get("pair_status") or "").strip().lower()
)
now_s = int(time.time())
# Runtime may process sends even when `connected` lags false briefly;
# heartbeat freshness is the reliable signal for queue availability.
@@ -3358,15 +3362,12 @@ class ComposeSend(LoginRequiredMixin, View):
level="warning",
panel_id=panel_id,
)
logger.info(f"{log_prefix} enqueuing runtime command (out-of-process)")
command_id = transport.enqueue_runtime_command(
base["service"],
"send_message_raw",
{"recipient": base["identifier"], "text": text, "attachments": []},
)
logger.info(
f"{log_prefix} command_id={command_id} enqueued, returning immediately"
)
logger.debug(f"{log_prefix} command_id={command_id} enqueued")
# attach command id to request so _response can include it in HX-Trigger
request._compose_command_id = command_id
# Do NOT wait here — return immediately so the UI doesn't block.
@@ -3374,14 +3375,12 @@ class ComposeSend(LoginRequiredMixin, View):
ts = int(time.time() * 1000)
else:
# In-process runtime can perform the send synchronously and return a timestamp.
logger.info(f"{log_prefix} calling in-process send_message_raw (blocking)")
ts = async_to_sync(transport.send_message_raw)(
base["service"],
base["identifier"],
text=text,
attachments=[],
)
logger.info(f"{log_prefix} in-process send returned ts={ts}")
# For queued sends we set `ts` to a local timestamp; for in-process sends ts may be False.
if not ts:
return self._response(
@@ -3397,13 +3396,12 @@ class ComposeSend(LoginRequiredMixin, View):
user=request.user,
identifier=base["person_identifier"],
)
logger.info(f"{log_prefix} session_id={session.id}")
# For in-process sends (Signal, etc), ts is a timestamp or True.
# For queued sends (WhatsApp/UR), ts is a local timestamp.
# Set delivered_ts only if we got a real timestamp OR if it's an in-process sync send.
msg_ts = int(ts) if str(ts).isdigit() else int(time.time() * 1000)
delivered_ts = msg_ts if runtime_client is not None else None
msg = Message.objects.create(
Message.objects.create(
user=request.user,
session=session,
sender_uuid="",
@@ -3412,9 +3410,6 @@ class ComposeSend(LoginRequiredMixin, View):
delivered_ts=delivered_ts,
custom_author="USER",
)
logger.info(
f"{log_prefix} created message id={msg.id} ts={msg_ts} delivered_ts={delivered_ts} custom_author=USER"
)
# Notify XMPP clients from runtime so cross-platform sends appear there too.
if base["service"] in {"signal", "whatsapp"}:
try: