mirror of
https://github.com/MarekWo/mc-webui.git
synced 2026-08-04 16:03:07 +02:00
fix(dm): persist delivery_path_hash_size so reloaded bubbles render multi-byte routes
Live dm_delivered_info already carried the correct hash_size, but the DB row only kept delivery_path. After a reload the API filled in path_hash_size from the incoming path_len column (NULL for outgoing DMs → default 1), so 2-byte routes were re-rendered as single-byte hops. Added a delivery_path_hash_size column (auto-migrated, defaults to 1) that update_dm_delivery_info now stores alongside the delivery path, populated from the same hash_size already known by each delivery path (retry ctx, PATH event, delayed contact backfill). /api/dm/messages returns the new field; dm.js prefers it over path_hash_size when rendering the Route line, falling back to the old field for legacy rows.
This commit is contained in:
+7
-4
@@ -51,6 +51,7 @@ class Database:
|
||||
('delivery_attempt', 'INTEGER'),
|
||||
('delivery_max_attempts', 'INTEGER'),
|
||||
('delivery_path', 'TEXT'),
|
||||
('delivery_path_hash_size', 'INTEGER DEFAULT 1'),
|
||||
]:
|
||||
if col not in dm_columns:
|
||||
conn.execute(f"ALTER TABLE direct_messages ADD COLUMN {col} {typedef}")
|
||||
@@ -788,13 +789,15 @@ class Database:
|
||||
return dict(row) if row else None
|
||||
|
||||
def update_dm_delivery_info(self, dm_id: int, attempt: int,
|
||||
max_attempts: int, path: str):
|
||||
"""Store successful delivery details (attempt number, path used)."""
|
||||
max_attempts: int, path: str,
|
||||
hash_size: int = 1):
|
||||
"""Store successful delivery details (attempt number, path used, hop byte size)."""
|
||||
with self._connect() as conn:
|
||||
conn.execute(
|
||||
"UPDATE direct_messages SET delivery_attempt=?, "
|
||||
"delivery_max_attempts=?, delivery_path=? WHERE id=?",
|
||||
(attempt, max_attempts, path, dm_id))
|
||||
"delivery_max_attempts=?, delivery_path=?, delivery_path_hash_size=? "
|
||||
"WHERE id=?",
|
||||
(attempt, max_attempts, path, hash_size, dm_id))
|
||||
|
||||
def update_dm_delivery_status(self, dm_id: int, status: str):
|
||||
"""Mark message delivery as failed."""
|
||||
|
||||
+10
-5
@@ -779,7 +779,8 @@ class DeviceManager:
|
||||
ctx = self._retry_context.pop(dm_id, None)
|
||||
if ctx:
|
||||
self.db.update_dm_delivery_info(
|
||||
dm_id, ctx['attempt'], ctx['max_attempts'], ctx['path'])
|
||||
dm_id, ctx['attempt'], ctx['max_attempts'], ctx['path'],
|
||||
ctx.get('hash_size', 1))
|
||||
if self.socketio:
|
||||
self.socketio.emit('dm_delivered_info', {
|
||||
'dm_id': dm_id,
|
||||
@@ -980,7 +981,8 @@ class DeviceManager:
|
||||
disc_hash_size = path_hash_mode + 1
|
||||
if ctx:
|
||||
self.db.update_dm_delivery_info(
|
||||
dm_id, ctx['attempt'], ctx['max_attempts'], discovered_path)
|
||||
dm_id, ctx['attempt'], ctx['max_attempts'], discovered_path,
|
||||
disc_hash_size)
|
||||
if self.socketio:
|
||||
self.socketio.emit('dm_delivered_info', {
|
||||
'dm_id': dm_id,
|
||||
@@ -1018,7 +1020,8 @@ class DeviceManager:
|
||||
if recent:
|
||||
self.db.update_dm_delivery_info(
|
||||
recent['id'], recent['delivery_attempt'],
|
||||
recent['delivery_max_attempts'], discovered_path)
|
||||
recent['delivery_max_attempts'], discovered_path,
|
||||
backfill_hash_size)
|
||||
if self.socketio:
|
||||
self.socketio.emit('dm_delivered_info', {
|
||||
'dm_id': recent['id'],
|
||||
@@ -1651,7 +1654,8 @@ class DeviceManager:
|
||||
dm_id,
|
||||
dm.get('delivery_attempt') or 1,
|
||||
dm.get('delivery_max_attempts') or 1,
|
||||
path_hex)
|
||||
path_hex,
|
||||
bf_hash_size)
|
||||
if self.socketio:
|
||||
self.socketio.emit('dm_delivered_info', {
|
||||
'dm_id': dm_id,
|
||||
@@ -1960,7 +1964,8 @@ class DeviceManager:
|
||||
ctx = self._retry_context.pop(dm_id, None)
|
||||
if ctx:
|
||||
self.db.update_dm_delivery_info(
|
||||
dm_id, ctx['attempt'], ctx['max_attempts'], ctx['path'])
|
||||
dm_id, ctx['attempt'], ctx['max_attempts'], ctx['path'],
|
||||
ctx.get('hash_size', 1))
|
||||
|
||||
# Mark delivery_status so reloading messages from DB shows delivered
|
||||
self.db.update_dm_delivery_status(dm_id, 'delivered')
|
||||
|
||||
@@ -2274,6 +2274,7 @@ def get_dm_messages():
|
||||
'delivery_attempt': row.get('delivery_attempt'),
|
||||
'delivery_max_attempts': row.get('delivery_max_attempts'),
|
||||
'delivery_path': row.get('delivery_path'),
|
||||
'delivery_path_hash_size': row.get('delivery_path_hash_size') or 1,
|
||||
'conversation_id': conversation_id,
|
||||
})
|
||||
else:
|
||||
|
||||
+2
-2
@@ -1234,7 +1234,7 @@ function displayMessages(messages) {
|
||||
if (msg.delivery_attempt && msg.delivery_max_attempts) {
|
||||
title += ` (${msg.delivery_attempt}/${msg.delivery_max_attempts})`;
|
||||
}
|
||||
const route = formatDmRoute(msg.delivery_path, msg.path_hash_size);
|
||||
const route = formatDmRoute(msg.delivery_path, msg.delivery_path_hash_size || msg.path_hash_size);
|
||||
if (route) title += `, Route: ${route}`;
|
||||
else if (msg.delivery_route) title += `, ${msg.delivery_route.replace('PATH_', '')}`;
|
||||
if (msg.delivery_snr !== null && msg.delivery_snr !== undefined) {
|
||||
@@ -1274,7 +1274,7 @@ function displayMessages(messages) {
|
||||
}
|
||||
// Show route only for delivered messages (not failed)
|
||||
if (msg.status === 'delivered') {
|
||||
const routeHtml = buildDmRouteHtml(msg.delivery_path, msg.path_hash_size);
|
||||
const routeHtml = buildDmRouteHtml(msg.delivery_path, msg.delivery_path_hash_size || msg.path_hash_size);
|
||||
if (routeHtml) {
|
||||
parts.push(routeHtml);
|
||||
} else if (msg.delivery_route) {
|
||||
|
||||
Reference in New Issue
Block a user