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

This commit is contained in:
2026-08-10 19:17:58 +10:00
parent f2d1acac35
commit 43ce4514c4
2 changed files with 8 additions and 6 deletions

View File

@@ -162,11 +162,13 @@ func (a *App) shouldAlert(ctx context.Context, tag db.Tag, scan db.Scan, hasLoc
// Within the window? // Within the window?
if time.Since(last.ScannedAt.Time) < alertWindow { 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 && moved := hasLoc && last.Lat.Valid && last.Lng.Valid &&
sms.HaversineMeters(last.Lat.Float64, last.Lng.Float64, *lat, *lng) > alertMinDistance sms.HaversineMeters(last.Lat.Float64, last.Lng.Float64, *lat, *lng) > alertMinDistance
locationUpgrade := hasLoc && !last.Lat.Valid
differentPhone := phone != "" && phone != last.ScannerPhone.String differentPhone := phone != "" && phone != last.ScannerPhone.String
return moved || differentPhone, "" return moved || locationUpgrade || differentPhone, ""
} }
return true, "" return true, ""
} }

View File

@@ -142,12 +142,12 @@
function () { function () {
sendScan(null, null); // no location — page still works, button stays 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-first: send coords when the finder approves. If the prompt is
// location is an upgrade, never a gate. // denied, unsupported, or silently blocked (8s), fall back to a plain scan
sendScan(null, null); // so every tag view still reports.
if (btn) btn.addEventListener("click", tryLocation); if (btn) btn.addEventListener("click", tryLocation);
tryLocation(); tryLocation();
})(); })();