mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-11-02 19:02:00 +00:00
feat(l1): Save per channel, and Keep messages Off deletes the log at the next start
Channel options > Save keeps a busy channel's new messages off the flash, so it leaves the room to the others; Keep messages stays the master switch. Off now only stops the saving, so a value stepped past costs nothing and the wait for the delete comes at a start. Delete history stays immediate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -259,6 +259,13 @@ static void setFavourite(NodePrefs* p, uint8_t idx, bool on) {
|
||||
if (on) p->ch_fav_bitmask |= 1ULL << idx; else p->ch_fav_bitmask &= ~(1ULL << idx);
|
||||
}
|
||||
|
||||
// Whether new messages of this channel go to the flash log (HistoryLog.h).
|
||||
static bool saved(const NodePrefs* p, uint8_t idx) { return !p || !(p->ch_no_save & (1ULL << idx)); }
|
||||
static void setSaved(NodePrefs* p, uint8_t idx, bool on) {
|
||||
if (!p) return;
|
||||
if (on) p->ch_no_save &= ~(1ULL << idx); else p->ch_no_save |= 1ULL << idx;
|
||||
}
|
||||
|
||||
// Scope as a picker row: 0 = Default (follow the list's default), then the
|
||||
// list itself from 1 ("*" = unscoped, then the named entries).
|
||||
static uint8_t scope(const NodePrefs* p, uint8_t idx) {
|
||||
@@ -274,8 +281,8 @@ static uint8_t scopeFromRow(int row) {
|
||||
// here, so a channel re-added at a freed slot can't inherit the old one's
|
||||
// settings. Adding such a field: clear it below (and mark it in NodePrefs.h).
|
||||
// Covers bot_channel_idx, loc_share_channel_idx, ch_notif_melody_*,
|
||||
// ch_notif_override / ch_notif_muted, ch_fav_bitmask, favourite dial slots,
|
||||
// ch_scope_idx. True when something changed (caller saves).
|
||||
// ch_notif_override / ch_notif_muted, ch_fav_bitmask, ch_no_save, favourite dial
|
||||
// slots, ch_scope_idx. True when something changed (caller saves).
|
||||
static bool onRemoved(NodePrefs* p, uint8_t idx) {
|
||||
if (!p) return false;
|
||||
bool changed = false;
|
||||
@@ -286,6 +293,7 @@ static bool onRemoved(NodePrefs* p, uint8_t idx) {
|
||||
if (p->ch_notif_melody_set & m) { p->ch_notif_melody_set &= ~m; p->ch_notif_melody_2 &= ~m; changed = true; }
|
||||
if (p->ch_notif_override & m) { p->ch_notif_override &= ~m; p->ch_notif_muted &= ~m; changed = true; }
|
||||
if (p->ch_fav_bitmask & m) { p->ch_fav_bitmask &= ~m; changed = true; }
|
||||
if (p->ch_no_save & m) { p->ch_no_save &= ~m; changed = true; }
|
||||
if (idx < NodePrefs::MAX_SCOPED_CHANNELS && p->ch_scope_idx[idx] != NodePrefs::CH_SCOPE_DEFAULT) {
|
||||
p->ch_scope_idx[idx] = NodePrefs::CH_SCOPE_DEFAULT; // back to Default, as a new channel
|
||||
changed = true;
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
// A record: Rec, the path, the text, then its own total length as one byte, so
|
||||
// the log can be walked from the end. restore() fills the RAM rings from there.
|
||||
// A channel's messages carry channelKey(), so they follow the channel, not the
|
||||
// slot; those of a channel since deleted aren't restored.
|
||||
// slot; those of a channel since deleted aren't restored. A channel with Save
|
||||
// off (chanctl::saved()) stays out of the log from then on; what it has there
|
||||
// stays until it ages out.
|
||||
//
|
||||
// Older messages, past what the rings hold, are read a page at a time
|
||||
// (pageBegin*(), pageOlder(), pageNewer()): the messages screen measures its
|
||||
@@ -54,6 +56,8 @@ public:
|
||||
if (_on) {
|
||||
scan();
|
||||
restore();
|
||||
} else if (_fs && _fs->exists(ROOT)) {
|
||||
forget(); // Keep messages off since the last start, see loop()
|
||||
}
|
||||
_next_prune = millis() + SAVE_DELAY_MS;
|
||||
history->setArchive(this);
|
||||
@@ -61,8 +65,12 @@ public:
|
||||
|
||||
// ── HistArchive ────────────────────────────────────────────────────────────
|
||||
// arc_id orders the entries of this run; a restored one keeps 0, already saved.
|
||||
void chAppend(ChHistEntry& e) override { e.arc_id = ++_seq; appended(); }
|
||||
void chUpdate(const ChHistEntry&) override { touch(); }
|
||||
void chAppend(ChHistEntry& e) override {
|
||||
if (!chanctl::saved(_prefs, e.ch_idx)) { e.arc_id = NOT_SAVED; return; }
|
||||
e.arc_id = ++_seq;
|
||||
appended();
|
||||
}
|
||||
void chUpdate(const ChHistEntry& e) override { if (e.arc_id != NOT_SAVED) touch(); }
|
||||
void dmAppend(DmHistEntry& e) override { e.arc_id = ++_seq; appended(); }
|
||||
void dmUpdate(const DmHistEntry&) override { touch(); }
|
||||
|
||||
@@ -70,7 +78,9 @@ public:
|
||||
bool on = _fs && _prefs && _prefs->msg_keep;
|
||||
if (on != _on) {
|
||||
_on = on;
|
||||
if (on) touch(); else forget();
|
||||
// Off only stops the saving; begin() deletes the log, so a value stepped
|
||||
// past on the way to another costs nothing, and the wait comes at a start.
|
||||
if (on) touch(); else _dirty = false;
|
||||
}
|
||||
if (_dirty && (int32_t)(millis() - _due) >= 0) flush(false);
|
||||
if (_on && (int32_t)(millis() - _next_prune) >= 0) {
|
||||
@@ -177,6 +187,9 @@ public:
|
||||
|
||||
private:
|
||||
static constexpr const char* ROOT = "/h";
|
||||
// arc_id of a message that stays in the ring: a channel with Save off. Above
|
||||
// any _ch_done, so it never counts as in the log (pageBeginCh).
|
||||
static const uint32_t NOT_SAVED = 0xFFFFFFFFUL;
|
||||
|
||||
struct __attribute__((packed)) Rec {
|
||||
uint32_t key; // channelKey(), or a DM's 4-byte public key prefix
|
||||
@@ -250,7 +263,7 @@ private:
|
||||
uint32_t now = rtc_clock.getCurrentTime();
|
||||
for (int j = _history->chHistCount() - 1; j >= 0; j--) {
|
||||
const ChHistEntry& e = _history->chAtPos(_history->chHistPosNewest(j));
|
||||
if (e.arc_id <= _ch_done) continue;
|
||||
if (e.arc_id <= _ch_done || e.arc_id == NOT_SAVED) continue;
|
||||
if (!all && e.relay_status == ACK_PENDING && now - e.timestamp < SETTLE_SECS) { more = true; break; }
|
||||
ChannelDetails ch;
|
||||
if (the_mesh.getChannel(e.ch_idx, ch) && ch.name[0] &&
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "MessageHistory.h"
|
||||
#ifdef HIST_FLASH
|
||||
#include "ChannelControl.h" // chanctl::saved()
|
||||
#include "HistoryLog.h"
|
||||
#endif
|
||||
#include "DmUnreadTable.h"
|
||||
|
||||
Reference in New Issue
Block a user