refactor(companion): dedup age formatting + reply-prefix parsing; drop dead code

Consolidation pass over the message/nearby UI, no functional change beyond
one intentional display tweak:

- Age tags: NearbyScreen::fmtAge, the nearby list's inline column, and
  QuickMsgScreen::fmtMsgAge each reimplemented the same s/m/h bucket ladder
  on top of geo::fmtAgeShort. All now delegate to it (fmtMsgAge removed).
  Visible effect: ages over 24h render as "Nd" instead of capped hours,
  matching the Locator target picker which already used fmtAgeShort.
- Reply prefix: the "@[nick] " parse was duplicated in skipReplyPrefix() and
  FullscreenMsgView::render(). Extracted to one msgReplyBody() helper (body,
  plus optional addressee nick) — one place to handle its edge cases.
- LiveTrack: the expiry predicate was duplicated in expire()/isActive();
  extracted to a private expired() helper.
- Removed a dead M_PI define (and unused <math.h>) in NearbyScreen.h, and a
  comment pointing at a CODE_REVIEW.md that doesn't exist.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
MarekZegare4
2026-06-29 17:43:17 +02:00
co-authored by Claude Opus 4.8
parent 31d602c88a
commit fe19d1b0a7
4 changed files with 52 additions and 66 deletions
+10 -10
View File
@@ -51,14 +51,9 @@ public:
}
// Drop entries not refreshed within EXPIRY_SECS. `now` is RTC epoch seconds.
// Guarded against now < ts (RTC stepped backwards) so a clock fix can't wipe
// the table.
void expire(uint32_t now) {
for (int i = 0; i < CAPACITY; i++) {
if (_e[i].used && now > _e[i].ts && (now - _e[i].ts) > EXPIRY_SECS) {
_e[i].used = false;
}
}
for (int i = 0; i < CAPACITY; i++)
if (_e[i].used && expired(_e[i], now)) _e[i].used = false;
}
void clear() { for (int i = 0; i < CAPACITY; i++) _e[i].used = false; }
@@ -66,9 +61,7 @@ public:
// Slot-wise access (caller skips inactive slots via isActive()).
const Entry& slotAt(int i) const { return _e[i]; }
bool isActive(int i, uint32_t now) const {
const Entry& e = _e[i];
if (!e.used) return false;
return !(now > e.ts && (now - e.ts) > EXPIRY_SECS);
return _e[i].used && !expired(_e[i], now);
}
// Number of currently non-expired entries.
@@ -94,6 +87,13 @@ public:
private:
Entry _e[CAPACITY] = {};
// An entry is stale once EXPIRY_SECS have passed since its last update.
// Guarded against now < ts (RTC stepped backwards) so a clock fix can't
// mass-expire the table.
static bool expired(const Entry& e, uint32_t now) {
return now > e.ts && (now - e.ts) > EXPIRY_SECS;
}
// Match an existing entry: verified shares by key, channel shares by name.
int find(const uint8_t* key, const char* name, bool verified) const {
for (int i = 0; i < CAPACITY; i++) {