mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-05-07 22:05:14 +02:00
First wave of work
This commit is contained in:
@@ -26,6 +26,7 @@ class MessageRepository:
|
||||
conversation_key: str,
|
||||
sender_timestamp: int | None = None,
|
||||
path: str | None = None,
|
||||
path_len: int | None = None,
|
||||
txt_type: int = 0,
|
||||
signature: str | None = None,
|
||||
outgoing: bool = False,
|
||||
@@ -43,7 +44,10 @@ class MessageRepository:
|
||||
# Convert single path to paths array format
|
||||
paths_json = None
|
||||
if path is not None:
|
||||
paths_json = json.dumps([{"path": path, "received_at": received_at}])
|
||||
normalized_path_len = path_len if isinstance(path_len, int) else len(path) // 2
|
||||
path_entry: dict[str, Any] = {"path": path, "received_at": received_at}
|
||||
path_entry["path_len"] = normalized_path_len
|
||||
paths_json = json.dumps([path_entry])
|
||||
|
||||
cursor = await db.conn.execute(
|
||||
"""
|
||||
@@ -74,7 +78,7 @@ class MessageRepository:
|
||||
|
||||
@staticmethod
|
||||
async def add_path(
|
||||
message_id: int, path: str, received_at: int | None = None
|
||||
message_id: int, path: str, received_at: int | None = None, path_len: int | None = None
|
||||
) -> list[MessagePath]:
|
||||
"""Add a new path to an existing message.
|
||||
|
||||
@@ -85,7 +89,10 @@ class MessageRepository:
|
||||
|
||||
# Atomic append: use json_insert to avoid read-modify-write race when
|
||||
# multiple duplicate packets arrive concurrently for the same message.
|
||||
new_entry = json.dumps({"path": path, "received_at": ts})
|
||||
normalized_path_len = path_len if isinstance(path_len, int) else len(path) // 2
|
||||
new_entry_dict: dict[str, Any] = {"path": path, "received_at": ts}
|
||||
new_entry_dict["path_len"] = normalized_path_len
|
||||
new_entry = json.dumps(new_entry_dict)
|
||||
await db.conn.execute(
|
||||
"""UPDATE messages SET paths = json_insert(
|
||||
COALESCE(paths, '[]'), '$[#]', json(?)
|
||||
|
||||
Reference in New Issue
Block a user