Fix several bugs found in code review

- DataStore: persist custom_msgs, ch_notif_override/muted, dm_show_all,
  room_fav_only — none were being saved/loaded, all settings lost on reboot.
  Load uses file.available() guard for backward compat with old saves.
- QuickMsgScreen reset(): clear _ctx_open/_ctx_dirty/_ctx_sel so context
  menu state is clean when re-entering the messaging screen.
- Remove unused _ctx_ch_idx field (code always uses _channel_indices[_channel_sel]).
- _room_unread: cap at _msgcount before incrementing to prevent badge
  going negative (getMsgCount() - getRoomUnreadCount()).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-05-11 19:34:07 +02:00
parent 4b06dff4e7
commit eea9254212
2 changed files with 18 additions and 5 deletions

View File

@@ -238,6 +238,13 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
file.read((uint8_t *)&_prefs.tz_offset_hours, sizeof(_prefs.tz_offset_hours)); // 140
file.read((uint8_t *)&_prefs.low_batt_mv, sizeof(_prefs.low_batt_mv)); // 141
file.read((uint8_t *)&_prefs.batt_display_mode, sizeof(_prefs.batt_display_mode)); // 143
if (file.available()) {
file.read((uint8_t *)_prefs.custom_msgs, sizeof(_prefs.custom_msgs)); // 144
file.read((uint8_t *)&_prefs.ch_notif_override, sizeof(_prefs.ch_notif_override)); // 1544
file.read((uint8_t *)&_prefs.ch_notif_muted, sizeof(_prefs.ch_notif_muted)); // 1552
file.read((uint8_t *)&_prefs.dm_show_all, sizeof(_prefs.dm_show_all)); // 1560
file.read((uint8_t *)&_prefs.room_fav_only, sizeof(_prefs.room_fav_only)); // 1561
}
file.close();
}
@@ -283,6 +290,11 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
file.write((uint8_t *)&_prefs.tz_offset_hours, sizeof(_prefs.tz_offset_hours)); // 140
file.write((uint8_t *)&_prefs.low_batt_mv, sizeof(_prefs.low_batt_mv)); // 141
file.write((uint8_t *)&_prefs.batt_display_mode, sizeof(_prefs.batt_display_mode)); // 143
file.write((uint8_t *)_prefs.custom_msgs, sizeof(_prefs.custom_msgs)); // 144
file.write((uint8_t *)&_prefs.ch_notif_override, sizeof(_prefs.ch_notif_override)); // 1544
file.write((uint8_t *)&_prefs.ch_notif_muted, sizeof(_prefs.ch_notif_muted)); // 1552
file.write((uint8_t *)&_prefs.dm_show_all, sizeof(_prefs.dm_show_all)); // 1560
file.write((uint8_t *)&_prefs.room_fav_only, sizeof(_prefs.room_fav_only)); // 1561
file.close();
}

View File

@@ -731,7 +731,6 @@ class QuickMsgScreen : public UIScreen {
// Context menu (opened by long-press ENTER in CHANNEL_PICK)
bool _ctx_open;
bool _ctx_dirty;
int _ctx_ch_idx;
int _ctx_sel;
struct ChHistEntry { uint8_t ch_idx; char text[140]; };
@@ -931,7 +930,7 @@ public:
_hist_head(0), _hist_count(0),
_kb_row(0), _kb_col(0), _kb_len(0),
_kb_caps(false), _kb_ph_mode(false), _kb_ph_sel(0),
_ctx_open(false), _ctx_dirty(false), _ctx_ch_idx(-1), _ctx_sel(0) {
_ctx_open(false), _ctx_dirty(false), _ctx_sel(0) {
_kb_text[0] = '\0';
memset(_ch_unread, 0, sizeof(_ch_unread));
}
@@ -974,8 +973,11 @@ public:
_room_mode = false;
buildContactList();
buildChannelList();
_ctx_open = false;
_ctx_dirty = false;
_ctx_sel = 0;
}
int render(DisplayDriver& display) override {
@@ -1456,7 +1458,6 @@ public:
return true;
}
if (c == KEY_CONTEXT_MENU && _num_channels > 0) {
_ctx_ch_idx = _channel_indices[_channel_sel];
_ctx_sel = 0;
_ctx_dirty = false;
_ctx_open = true;
@@ -2379,7 +2380,7 @@ void UITask::msgRead(int msgcount) {
void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount, uint8_t contact_type) {
_msgcount = msgcount;
if (contact_type == ADV_TYPE_ROOM) _room_unread++;
if (contact_type == ADV_TYPE_ROOM && _room_unread < _msgcount) _room_unread++;
char alert_buf[80];
snprintf(alert_buf, sizeof(alert_buf), "Msg: %.20s", from_name);