mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-05-24 23:01:22 -04:00
Fix Phase 2b edge case: mostRecentPacketTime when all nodes have lastHeard=0
- Add takeIf check to distinguish lastHeard=0 (never heard) from no nodes
- Previously: maxOfOrNull returns 0, Elvis operator doesn't trigger (0 is not null)
- Now: takeIf { it > 0 } filters out zero, falling back to current time
- Ensures API returns meaningful timestamp instead of epoch 1970
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -260,7 +260,10 @@ class AiFunctionProviderImpl(
|
||||
|
||||
// Find most recent packet: max lastHeard across all nodes (convert seconds to ms)
|
||||
val mostRecentPacketTimeMs =
|
||||
nodeMap.values.maxOfOrNull { it.lastHeard }?.toLong()?.times(MS_PER_SEC)
|
||||
nodeMap.values.maxOfOrNull { it.lastHeard }
|
||||
?.takeIf { it > 0 }
|
||||
?.toLong()
|
||||
?.times(MS_PER_SEC)
|
||||
?: clock.now().toEpochMilliseconds()
|
||||
|
||||
// Get local device uptime from its DeviceMetrics (node #0 is typically the local device)
|
||||
|
||||
Reference in New Issue
Block a user