fix: ON AIR badge correct at launch + faster to appear
At launch nothing is in memory yet, so the badge showed offline even with a recent QSO. liveLastQSOTime is now authoritative: it takes the most recent of the in-memory stamp AND the DB (this operator's last QSO — covers a contact from the shared logbook or one logged before launch), used by both the published status and the badge. The badge polls the backend every 5 s (down from 15) and on each qso:logged, so it shows on air within a few seconds and flips online instantly on a new contact.
This commit is contained in:
+21
-4
@@ -87,12 +87,29 @@ func (a *App) seedLiveLastQSO() {
|
||||
}
|
||||
}
|
||||
|
||||
// LiveLastQSOAgeSec returns seconds since this operator's last logged QSO, or -1 if
|
||||
// none is known — the UI uses it to seed the "on air" badge at launch.
|
||||
func (a *App) LiveLastQSOAgeSec() int {
|
||||
// liveLastQSOTime is the authoritative "last contact" instant for this operator:
|
||||
// the most recent of the in-memory stamp (this session's local logs, updated
|
||||
// instantly) AND the DB (a contact that arrived via the SHARED logbook from another
|
||||
// station, or one logged before launch). Used by both the published status and the
|
||||
// UI badge so on-air/offline is right in every multi-op case.
|
||||
func (a *App) liveLastQSOTime() time.Time {
|
||||
a.liveActMu.Lock()
|
||||
last := a.liveLastQSOAt
|
||||
a.liveActMu.Unlock()
|
||||
if a.qso != nil {
|
||||
if op, _ := a.liveStatusOperator(); op != "" {
|
||||
if t, ok := a.qso.LastQSOTime(a.ctx, op); ok && t.After(last) {
|
||||
last = t
|
||||
}
|
||||
}
|
||||
}
|
||||
return last
|
||||
}
|
||||
|
||||
// LiveLastQSOAgeSec returns seconds since this operator's last logged QSO, or -1 if
|
||||
// none is known — the UI polls it for the "on air" badge.
|
||||
func (a *App) LiveLastQSOAgeSec() int {
|
||||
last := a.liveLastQSOTime()
|
||||
if last.IsZero() {
|
||||
return -1
|
||||
}
|
||||
@@ -182,8 +199,8 @@ func (a *App) publishLiveStatus() {
|
||||
if mode == "" {
|
||||
mode = a.liveMode
|
||||
}
|
||||
lastQSO := a.liveLastQSOAt
|
||||
a.liveActMu.Unlock()
|
||||
lastQSO := a.liveLastQSOTime() // authoritative (in-memory OR shared DB)
|
||||
// Online = a new contact was logged within the window. An operator who leaves
|
||||
// the log open but stops working shows offline after `liveOnlineWindow`; the
|
||||
// next QSO flips them back on. never-logged (zero time) → offline.
|
||||
|
||||
Reference in New Issue
Block a user