refactor(companion): register persistence hooks via message events

Use openhop_core's new single-argument event registrations for the
frame server's SQLite persistence callbacks instead of the deprecated
positional on_*_received forms.
This commit is contained in:
agessaman
2026-07-15 00:31:32 -07:00
parent 697056aa93
commit 9a2559a253
2 changed files with 12 additions and 9 deletions
+3 -3
View File
@@ -57,9 +57,9 @@ class CompanionFrameServer(_BaseFrameServer):
async def start(self) -> None:
"""Start persistence before accepting companion client connections."""
if self.sqlite_handler:
self.bridge.on_message_received(self._on_message_received)
self.bridge.on_channel_message_received(self._on_channel_message_received)
self.bridge.on_channel_data_received(self._on_channel_data_received)
self.bridge.on_message_event(self._on_message_event)
self.bridge.on_channel_message_event(self._on_channel_message_event)
self.bridge.on_channel_data_event(self._on_channel_data_event)
await super().start()
# -----------------------------------------------------------------
+9 -6
View File
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from openhop_core.companion.constants import PUSH_CODE_MSG_WAITING, RESP_CODE_NO_MORE_MESSAGES
from openhop_core.companion.models import MessageEvent
from repeater.companion.bridge import RepeaterCompanionBridge, _to_json_safe
from repeater.companion.frame_server import CompanionFrameServer
@@ -241,12 +242,14 @@ async def test_rejected_queue_callback_skips_sqlite_persistence_but_notifies_cli
server._persist_companion_message = AsyncMock()
server._enqueue_frame = MagicMock()
await server._on_message_received(
b"\x01" * 32,
"rejected",
1,
0,
queued=False,
await server._on_message_event(
MessageEvent(
sender_key=b"\x01" * 32,
text="rejected",
timestamp=1,
txt_type=0,
queued=False,
)
)
server._persist_companion_message.assert_not_awaited()