mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-08-03 10:46:12 +00:00
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:
co-authored by
Claude Opus 4.8
parent
31d602c88a
commit
fe19d1b0a7
@@ -10,12 +10,35 @@ static const int FS_CHARS_MAX = 80; // max bytes per wrapped line
|
||||
// fullscreen message view and the history list are never laid out in the same
|
||||
// frame (opening the fullscreen view early-returns before the list loop runs),
|
||||
// so one static buffer serves both. This keeps ~1.5 KB of line buffers off the
|
||||
// render-call stack (see CODE_REVIEW.md "Render-path stack peak") at the cost of
|
||||
// a fixed RAM allocation. Only used inside render()/wrap helpers — never across
|
||||
// a yield, so the single instance is safe.
|
||||
// render-call stack at the cost of a fixed RAM allocation. Only used inside
|
||||
// render()/wrap helpers — never across a yield, so the single instance is safe.
|
||||
static char s_wrap_trans[512];
|
||||
static char s_wrap_lines[12][FS_CHARS_MAX];
|
||||
|
||||
// Parse a leading "@[nick] " reply prefix. Returns the message body that
|
||||
// follows it (and any leading whitespace); when nick/nick_n are supplied,
|
||||
// fills nick with the addressee, or "" when there's no prefix. One parser for
|
||||
// both the history list (body only — see QuickMsgScreen::skipReplyPrefix) and
|
||||
// the fullscreen view (which also shows the "To:" nick).
|
||||
static inline const char* msgReplyBody(const char* text, char* nick = nullptr, int nick_n = 0) {
|
||||
if (nick && nick_n > 0) nick[0] = '\0';
|
||||
const char* body = text;
|
||||
if (text[0] == '@' && text[1] == '[') {
|
||||
const char* close = strchr(text + 2, ']');
|
||||
if (close && close[1] == ' ' && close[2]) {
|
||||
if (nick && nick_n > 0) {
|
||||
int len = (int)(close - text) - 2;
|
||||
if (len > nick_n - 1) len = nick_n - 1;
|
||||
memcpy(nick, text + 2, len);
|
||||
nick[len] = '\0';
|
||||
}
|
||||
body = close + 2;
|
||||
}
|
||||
}
|
||||
while (*body == '\n' || *body == '\r' || *body == ' ') body++;
|
||||
return body;
|
||||
}
|
||||
|
||||
struct FullscreenMsgView {
|
||||
int scroll;
|
||||
bool active;
|
||||
@@ -80,19 +103,9 @@ struct FullscreenMsgView {
|
||||
const int lineH = display.getLineHeight();
|
||||
const int max_px = display.width() - 6;
|
||||
|
||||
// detect @recipient at start of message
|
||||
char to_nick[32] = "";
|
||||
const char* body = text;
|
||||
if (text[0] == '@' && text[1] == '[') {
|
||||
const char* close = strchr(text + 2, ']');
|
||||
if (close && close[1] == ' ' && close[2]) {
|
||||
int len = (int)(close - text) - 2;
|
||||
if (len >= (int)sizeof(to_nick)) len = sizeof(to_nick) - 1;
|
||||
memcpy(to_nick, text + 2, len);
|
||||
to_nick[len] = '\0';
|
||||
body = close + 2;
|
||||
}
|
||||
}
|
||||
// "@[nick] " reply prefix → "To:" header + body (shared parser).
|
||||
char to_nick[32];
|
||||
const char* body = msgReplyBody(text, to_nick, sizeof(to_nick));
|
||||
|
||||
const int cw = display.getCharWidth();
|
||||
const int header_h = to_nick[0] ? (lineH * 2 + 4) : (lineH + 2);
|
||||
|
||||
Reference in New Issue
Block a user