From 606f28c34aa60117b399b2098ded772f69d3c730 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Thu, 4 Jun 2026 12:10:26 +0200 Subject: [PATCH] fix(messages): stop clipping long received messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message history buffers were smaller than the over-the-air maximum, so long messages lost their tail on display. Channel messages carry the sender embedded as "Name: body" in the payload (up to MAX_TEXT_LEN = 160 B), but ChHistEntry::text was only 140 B; DmHistEntry::text was just 80 B — and with Polish text each accented char is two UTF-8 bytes, so the effective limit was roughly half the visible characters. Size both history buffers (and the fullscreen/preview split copies) to MAX_TEXT_LEN + 1 so a full-length message is stored and shown intact. Sender split buffers widened to the 32-char name limit. Co-Authored-By: Claude Opus 4.8 --- .../companion_radio/ui-new/QuickMsgScreen.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/companion_radio/ui-new/QuickMsgScreen.h b/examples/companion_radio/ui-new/QuickMsgScreen.h index 64db5c13..05dd5418 100644 --- a/examples/companion_radio/ui-new/QuickMsgScreen.h +++ b/examples/companion_radio/ui-new/QuickMsgScreen.h @@ -78,12 +78,19 @@ class QuickMsgScreen : public UIScreen { bool _share_mode = false; char _share_text[160] = ""; - struct ChHistEntry { uint8_t ch_idx; char text[140]; uint32_t timestamp; }; + // History text holds a full received message. Channel messages carry the + // sender embedded as "Name: body" in the payload, so a message can be up to + // the over-the-air maximum (MAX_TEXT_LEN). Size the buffers to that + NUL, + // otherwise long messages (and Polish text, where each accented char is two + // UTF-8 bytes) get their tail clipped. + static const int MSG_TEXT_BUF = MAX_TEXT_LEN + 1; + + struct ChHistEntry { uint8_t ch_idx; char text[MSG_TEXT_BUF]; uint32_t timestamp; }; ChHistEntry _hist[CH_HIST_MAX]; int _hist_head, _hist_count; // DM_HIST - struct DmHistEntry { uint8_t prefix[4]; uint8_t outgoing; char text[80]; uint32_t timestamp; }; + struct DmHistEntry { uint8_t prefix[4]; uint8_t outgoing; char text[MSG_TEXT_BUF]; uint32_t timestamp; }; static const int DM_HIST_MAX = 64; DmHistEntry _dm_hist[DM_HIST_MAX]; int _dm_hist_head, _dm_hist_count; @@ -891,9 +898,9 @@ public: if (ring_pos >= 0) { const char* ftext = _hist[ring_pos].text; const char* fsep = strstr(ftext, ": "); - char fsender[22], fmsg[140]; + char fsender[33], fmsg[MSG_TEXT_BUF]; if (fsep) { - int nl = fsep - ftext; if (nl > 21) nl = 21; + int nl = fsep - ftext; if (nl > (int)sizeof(fsender) - 1) nl = sizeof(fsender) - 1; strncpy(fsender, ftext, nl); fsender[nl] = '\0'; strncpy(fmsg, fsep + 2, sizeof(fmsg) - 1); fmsg[sizeof(fmsg)-1] = '\0'; } else { @@ -963,9 +970,9 @@ public: const char* text = _hist[ring_pos].text; const char* sep = strstr(text, ": "); - char sender[22], msg_part[140]; + char sender[33], msg_part[MSG_TEXT_BUF]; if (sep) { - int nl = sep - text; if (nl > 21) nl = 21; + int nl = sep - text; if (nl > (int)sizeof(sender) - 1) nl = sizeof(sender) - 1; strncpy(sender, text, nl); sender[nl] = '\0'; strncpy(msg_part, sep + 2, sizeof(msg_part) - 1); msg_part[sizeof(msg_part) - 1] = '\0';