From a61e271e9a752fcaad9bbd0e789db5acbc19ab16 Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Tue, 10 Feb 2026 21:09:29 -0800 Subject: [PATCH] Fix falsy zero lat/lon bug --- app/models.py | 6 +++--- app/repository.py | 14 +++++++------- frontend/src/components/MapView.tsx | 3 ++- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/models.py b/app/models.py index c4e9a03..d3b9be9 100644 --- a/app/models.py +++ b/app/models.py @@ -31,9 +31,9 @@ class Contact(BaseModel): "flags": self.flags, "out_path": self.last_path or "", "out_path_len": self.last_path_len, - "adv_lat": self.lat or 0.0, - "adv_lon": self.lon or 0.0, - "last_advert": self.last_advert or 0, + "adv_lat": self.lat if self.lat is not None else 0.0, + "adv_lon": self.lon if self.lon is not None else 0.0, + "last_advert": self.last_advert if self.last_advert is not None else 0, } @staticmethod diff --git a/app/repository.py b/app/repository.py index 4eb00e4..9d7b432 100644 --- a/app/repository.py +++ b/app/repository.py @@ -51,8 +51,8 @@ class ContactRepository: if "last_path_len" in contact else contact.get("out_path_len", -1), contact.get("last_advert"), - contact.get("lat") or contact.get("adv_lat"), - contact.get("lon") or contact.get("adv_lon"), + contact.get("lat") if contact.get("lat") is not None else contact.get("adv_lat"), + contact.get("lon") if contact.get("lon") is not None else contact.get("adv_lon"), contact.get("last_seen", int(time.time())), contact.get("on_radio", False), contact.get("last_contacted"), @@ -162,7 +162,7 @@ class ContactRepository: @staticmethod async def update_last_contacted(public_key: str, timestamp: int | None = None) -> None: """Update the last_contacted timestamp for a contact.""" - ts = timestamp or int(time.time()) + ts = timestamp if timestamp is not None else int(time.time()) await db.conn.execute( "UPDATE contacts SET last_contacted = ?, last_seen = ? WHERE public_key = ?", (ts, ts, public_key.lower()), @@ -175,7 +175,7 @@ class ContactRepository: Returns True if a row was updated, False if contact not found. """ - ts = timestamp or int(time.time()) + ts = timestamp if timestamp is not None else int(time.time()) cursor = await db.conn.execute( "UPDATE contacts SET last_read_at = ? WHERE public_key = ?", (ts, public_key.lower()), @@ -266,7 +266,7 @@ class ChannelRepository: Returns True if a row was updated, False if channel not found. """ - ts = timestamp or int(time.time()) + ts = timestamp if timestamp is not None else int(time.time()) cursor = await db.conn.execute( "UPDATE channels SET last_read_at = ? WHERE key = ?", (ts, key.upper()), @@ -350,7 +350,7 @@ class MessageRepository: This is used when a repeat/echo of a message arrives via a different route. Returns the updated list of paths. """ - ts = received_at or int(time.time()) + ts = received_at if received_at is not None else int(time.time()) # Get current paths cursor = await db.conn.execute("SELECT paths FROM messages WHERE id = ?", (message_id,)) @@ -605,7 +605,7 @@ class RawPacketRepository: Deduplication is based on the SHA-256 hash of the packet payload (excluding routing/path information). """ - ts = timestamp or int(time.time()) + ts = timestamp if timestamp is not None else int(time.time()) # Compute payload hash for deduplication payload = extract_payload(data) diff --git a/frontend/src/components/MapView.tsx b/frontend/src/components/MapView.tsx index 899aa19..bddd5cc 100644 --- a/frontend/src/components/MapView.tsx +++ b/frontend/src/components/MapView.tsx @@ -4,6 +4,7 @@ import type { LatLngBoundsExpression, CircleMarker as LeafletCircleMarker } from import 'leaflet/dist/leaflet.css'; import type { Contact } from '../types'; import { formatTime } from '../utils/messageParser'; +import { isValidLocation } from '../utils/pathUtils'; import { CONTACT_TYPE_REPEATER } from '../types'; interface MapViewProps { @@ -97,7 +98,7 @@ export function MapView({ contacts, focusedKey }: MapViewProps) { const mappableContacts = useMemo(() => { const sevenDaysAgo = Date.now() / 1000 - 7 * 24 * 60 * 60; return contacts.filter( - (c) => c.lat != null && c.lon != null && c.last_seen != null && c.last_seen > sevenDaysAgo + (c) => isValidLocation(c.lat, c.lon) && c.last_seen != null && c.last_seen > sevenDaysAgo ); }, [contacts]);