From 43ce4514c4daba2ac58851b338626fb6ab396aa6 Mon Sep 17 00:00:00 2001 From: Sam Rolfe Date: Mon, 10 Aug 2026 19:17:58 +1000 Subject: [PATCH] location-first scan: geolocation prompt decides the scan (8s fallback to plain scan, never blocks); server 'location upgrade' rule re-alerts with map link when coords arrive after a no-loc alert --- frontend/internal/handlers/scan.go | 6 ++++-- frontend/templates/tag-public.html | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/internal/handlers/scan.go b/frontend/internal/handlers/scan.go index 7a161cc..1a51857 100644 --- a/frontend/internal/handlers/scan.go +++ b/frontend/internal/handlers/scan.go @@ -162,11 +162,13 @@ func (a *App) shouldAlert(ctx context.Context, tag db.Tag, scan db.Scan, hasLoc // Within the window? if time.Since(last.ScannedAt.Time) < alertWindow { - // Re-alert on movement >250 m, or a different finder phone. + // Re-alert on movement >250 m, a different finder phone, or a location + // upgrade (previous alert had no coords — send the map link). moved := hasLoc && last.Lat.Valid && last.Lng.Valid && sms.HaversineMeters(last.Lat.Float64, last.Lng.Float64, *lat, *lng) > alertMinDistance + locationUpgrade := hasLoc && !last.Lat.Valid differentPhone := phone != "" && phone != last.ScannerPhone.String - return moved || differentPhone, "" + return moved || locationUpgrade || differentPhone, "" } return true, "" } diff --git a/frontend/templates/tag-public.html b/frontend/templates/tag-public.html index e24462c..584ec65 100644 --- a/frontend/templates/tag-public.html +++ b/frontend/templates/tag-public.html @@ -142,12 +142,12 @@ function () { sendScan(null, null); // no location — page still works, button stays }, - {timeout: 20000, maximumAge: 0} + {timeout: 8000, maximumAge: 0} ); } - // Fire a scan immediately so a tag view always reports (and alerts) — - // location is an upgrade, never a gate. - sendScan(null, null); + // Location-first: send coords when the finder approves. If the prompt is + // denied, unsupported, or silently blocked (8s), fall back to a plain scan + // so every tag view still reports. if (btn) btn.addEventListener("click", tryLocation); tryLocation(); })();