fix(companion): hashtag join trims like the app, prefs survive a downgrade, a sender named Me

- Joining #topic drops surrounding spaces and keeps the case, as
  meshcore-open's derivePskFromHashtag() does.
- /prefs written by a newer build (bigger NodePrefs, same version): the
  extra bytes are read through the CRC and skipped instead of resetting
  every setting.
- A channel post from someone named "Me" is filed as "\"Me\": ...", so
  the views don't take it for our own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-10-12 18:14:08 +02:00
co-authored by Claude Opus 5.5
parent 01a068be7d
commit 4eee794a17
3 changed files with 25 additions and 3 deletions
@@ -113,11 +113,17 @@ static Result addPublic() {
}
// "#topic": name and passphrase both "#topic" (a leading '#' typed is kept once).
// Spaces around it are dropped and the case kept, as the phone app does
// (meshcore-open's derivePskFromHashtag()), so "#Kraków " joins the same channel.
static Result addHashtag(const char* topic) {
if (topic && topic[0] == '#') topic++;
if (!topic || !topic[0]) return NO_NAME;
if (!topic) return NO_NAME;
while (*topic == ' ') topic++;
if (topic[0] == '#') topic++;
char name[32];
snprintf(name, sizeof(name), "#%s", topic);
size_t n = strlen(name);
while (n > 1 && name[n - 1] == ' ') name[--n] = '\0';
if (n < 2) return NO_NAME;
uint8_t secret[32];
phraseToSecret(name, secret);
return save(freeSlot(), name, secret);
@@ -246,6 +246,11 @@ public:
}
void onChannelMessageRecvEx(mesh::Packet *pkt, uint8_t channel_idx, ChannelDetails& channel_details,
uint32_t timestamp, const char* text) override {
// Our own posts are filed as "Me: ..." and every view reads that prefix as
// "ours". Someone else named "Me" gets quotes, so theirs stays theirs (a
// bubble on the left, counted unread).
char quoted[MSG_TEXT_BUF];
if (strncmp(text, "Me: ", 4) == 0) { snprintf(quoted, sizeof(quoted), "\"Me\"%s", text + 2); text = quoted; }
addChannelMsg(channel_idx, text, timestamp, pkt->path, (uint8_t)pkt->path_len);
pushMessageArrived(UIEventType::channelMessage, channel_details.name, channel_idx);
}