fix(NearbyScreen): sort "?" entries to bottom in TIME filter

Contacts with lastmod=0 or lastmod>now (RTC not synced after reboot but
contacts have timestamps from a prior session) were sorted to the top
because their raw lastmod > 0. Now both cases are normalised to 0 before
the comparison, so unknown-time entries always appear at the bottom.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-06-09 17:23:50 +02:00
parent 562cef3261
commit 231b3c0e0d

View File

@@ -139,11 +139,14 @@ class NearbyScreen : public UIScreen {
e.lastmod = ci.lastmod; e.lastmod = ci.lastmod;
} }
uint32_t _now_ts = rtc_clock.getCurrentTime();
for (int i = 0; i < _count - 1; i++) { for (int i = 0; i < _count - 1; i++) {
int best = i; int best = i;
for (int j = i + 1; j < _count; j++) { for (int j = i + 1; j < _count; j++) {
if (_filter == FILTER_COUNT - 1) { if (_filter == FILTER_COUNT - 1) {
uint32_t tj = _entries[j].lastmod, tb = _entries[best].lastmod; // Treat lastmod=0 or lastmod>now (RTC not synced) as "unknown" → sort to bottom.
uint32_t tj = (_entries[j].lastmod > 0 && _now_ts >= _entries[j].lastmod) ? _entries[j].lastmod : 0;
uint32_t tb = (_entries[best].lastmod > 0 && _now_ts >= _entries[best].lastmod) ? _entries[best].lastmod : 0;
if (tj > 0 && (tb == 0 || tj > tb)) best = j; // descending — most recent first if (tj > 0 && (tb == 0 || tj > tb)) best = j; // descending — most recent first
} else { } else {
float dj = _entries[j].dist_km, db = _entries[best].dist_km; float dj = _entries[j].dist_km, db = _entries[best].dist_km;