diff --git a/app/routes/api.py b/app/routes/api.py index a6192dc..4e3188e 100644 --- a/app/routes/api.py +++ b/app/routes/api.py @@ -308,6 +308,8 @@ def get_messages(): resp_data = response.json() echo_counts = resp_data.get('echo_counts', []) incoming_paths = resp_data.get('incoming_paths', []) + if incoming_paths: + logger.debug(f"Echo data: {len(echo_counts)} sent, {len(incoming_paths)} incoming paths from bridge") # Merge sent echo counts + paths into own messages for msg in messages: @@ -322,13 +324,24 @@ def get_messages(): break # Merge incoming paths into received messages + # Match by timestamp proximity + path_len confirmation for msg in messages: if not msg.get('is_own'): + best_match = None + best_delta = 10 # max 10 second window for ip in incoming_paths: - if (abs(msg['timestamp'] - ip['timestamp']) < 5 and - msg.get('path_len') == ip.get('path_len')): - msg['path'] = ip['path'] - break + delta = abs(msg['timestamp'] - ip['timestamp']) + if delta < best_delta: + # Prefer matches where path_len also matches + if msg.get('path_len') == ip.get('path_len'): + best_match = ip + best_delta = delta + elif best_match is None: + # Fallback: timestamp-only match + best_match = ip + best_delta = delta + if best_match: + msg['path'] = best_match['path'] except Exception as e: logger.debug(f"Echo data fetch failed (non-critical): {e}") diff --git a/app/static/js/app.js b/app/static/js/app.js index b955629..22146b6 100644 --- a/app/static/js/app.js +++ b/app/static/js/app.js @@ -726,12 +726,13 @@ function createMessageElement(msg) { if (msg.is_own) { // Own messages: right-aligned, no avatar - // Echo badge shows how many repeaters heard the message + their path codes - const echoPaths = (msg.echo_paths || []).map(p => p.substring(0, 2)); + // Echo badge shows unique repeaters that heard the message + their path codes + const echoPaths = [...new Set((msg.echo_paths || []).map(p => p.substring(0, 2)))]; + const echoCount = echoPaths.length; const pathDisplay = echoPaths.length > 0 ? ` (${echoPaths.join(', ')})` : ''; - const echoDisplay = msg.echo_count > 0 - ? ` - ${msg.echo_count}${pathDisplay} + const echoDisplay = echoCount > 0 + ? ` + ${echoCount}${pathDisplay} ` : '';