mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-03-28 17:43:05 +01:00
27 lines
873 B
Python
27 lines
873 B
Python
"""Shared direct-message ACK application logic."""
|
|
|
|
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
from app.services import dm_ack_tracker
|
|
from app.services.messages import increment_ack_and_broadcast
|
|
|
|
BroadcastFn = Callable[..., Any]
|
|
|
|
|
|
async def apply_dm_ack_code(ack_code: str, *, broadcast_fn: BroadcastFn) -> bool:
|
|
"""Apply a DM ACK code using the shared pending/buffered state machine.
|
|
|
|
Returns True when the ACK matched a pending message, False when it was buffered.
|
|
"""
|
|
dm_ack_tracker.cleanup_expired_acks()
|
|
|
|
message_id = dm_ack_tracker.pop_pending_ack(ack_code)
|
|
if message_id is None:
|
|
dm_ack_tracker.buffer_unmatched_ack(ack_code)
|
|
return False
|
|
|
|
dm_ack_tracker.clear_pending_acks_for_message(message_id)
|
|
await increment_ack_and_broadcast(message_id=message_id, broadcast_fn=broadcast_fn)
|
|
return True
|