mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-10-14 09:33:16 +00:00
feat(ui-core,ui-lvgl): channel management in the Core, L2 channel screens
ChannelControl (add Public/Hashtag/Private, rename, delete, notif/fav/scope) and Favourites slots move into ui-core; ui-new uses them. Contact / channel pref cleanup moves from ui-new's UITask into UiCore so it runs on every frontend (L2 had none). L2: channel options popup (hold a row or the gear in a channel) and the Add / Edit channel form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2893,104 +2893,6 @@ void UITask::setTargetNow(uint8_t kind, const uint8_t* key, int32_t lat, int32_t
|
||||
void UITask::clearTarget() { _core->locator.clearTarget(); }
|
||||
void UITask::clearTargetIfWaypoint(int32_t lat_1e6, int32_t lon_1e6) { _core->locator.clearTargetIfWaypoint(lat_1e6, lon_1e6); }
|
||||
|
||||
// CONTRACT: every NodePrefs field that keys on a contact pubkey/prefix is
|
||||
// cleared here, so a removed contact can't leave a dangling reference. If you
|
||||
// add such a field, add its cleanup below (and mark the field in NodePrefs.h).
|
||||
// Currently covered: favourite_contacts, locator_key, loc_share_dm_prefix,
|
||||
// dm_notif[], dm_melody[]. Also clears the DM unread table (RAM-only, not a
|
||||
// NodePrefs field, so no savePrefs() needed for it) -- same 4-byte-prefix
|
||||
// shape and same 16-slot starvation risk as dm_notif/dm_melody above. Called
|
||||
// for both explicit removal and silent auto-eviction (see MyMesh
|
||||
// CMD_REMOVE_CONTACT / onContactOverwrite).
|
||||
void UITask::onContactRemoved(const uint8_t* pub_key) {
|
||||
if (!_node_prefs || !pub_key) return;
|
||||
bool changed = false;
|
||||
|
||||
clearDMUnread(pub_key);
|
||||
|
||||
int slot = findFavouriteSlot(pub_key);
|
||||
if (slot >= 0) { clearFavouriteSlot(slot); changed = true; }
|
||||
|
||||
if (_core->locator.onContactRemoved(pub_key)) changed = true;
|
||||
// Fail closed rather than guess a new recipient: a contact target that's
|
||||
// gone just turns auto-share off, it doesn't fall back to some other target.
|
||||
if (_node_prefs->loc_share_target_type == 1
|
||||
&& memcmp(_node_prefs->loc_share_dm_prefix, pub_key, NodePrefs::FAVOURITE_PREFIX_LEN) == 0) {
|
||||
_node_prefs->loc_share_enabled = 0;
|
||||
changed = true;
|
||||
}
|
||||
// Same fail-closed rule for the room bot's target: the room contact is
|
||||
// gone, disable it rather than risk a re-added contact silently inheriting
|
||||
// the old bot config.
|
||||
if (_node_prefs->bot_room_enabled
|
||||
&& memcmp(_node_prefs->bot_room_prefix, pub_key, NodePrefs::FAVOURITE_PREFIX_LEN) == 0) {
|
||||
_node_prefs->bot_room_enabled = 0;
|
||||
changed = true;
|
||||
}
|
||||
// Per-contact mute/melody overrides — only 16 slots shared across every
|
||||
// contact, so an orphaned entry isn't just stale, it can eventually starve
|
||||
// new overrides for contacts that still exist. Keyed by a 4-byte prefix
|
||||
// (narrower than the 6-byte one above), so compare only that many bytes.
|
||||
for (int i = 0; i < NodePrefs::DM_NOTIF_TABLE_MAX; i++) {
|
||||
if (_node_prefs->dm_notif[i].state && memcmp(_node_prefs->dm_notif[i].prefix, pub_key, 4) == 0) {
|
||||
memset(&_node_prefs->dm_notif[i], 0, sizeof(_node_prefs->dm_notif[i]));
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < NodePrefs::DM_MELODY_TABLE_MAX; i++) {
|
||||
if (_node_prefs->dm_melody[i].slot && memcmp(_node_prefs->dm_melody[i].prefix, pub_key, 4) == 0) {
|
||||
memset(&_node_prefs->dm_melody[i], 0, sizeof(_node_prefs->dm_melody[i]));
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) the_mesh.savePrefs();
|
||||
}
|
||||
|
||||
// CONTRACT: every NodePrefs field that keys on a channel index is cleared here,
|
||||
// so a channel re-added at a freed slot can't inherit the old one's settings.
|
||||
// If you add such a field, add its cleanup below (and mark it in NodePrefs.h).
|
||||
// Currently covered: bot_channel_idx, loc_share_channel_idx, ch_notif_melody_*,
|
||||
// ch_notif_override/ch_notif_muted, ch_fav_bitmask, favourite_contacts/_kinds,
|
||||
// ch_scope_idx.
|
||||
void UITask::onChannelRemoved(uint8_t channel_idx) {
|
||||
if (!_node_prefs) return;
|
||||
bool changed = false;
|
||||
|
||||
if (_node_prefs->bot_channel_enabled && _node_prefs->bot_channel_idx == channel_idx) {
|
||||
_node_prefs->bot_channel_enabled = 0;
|
||||
changed = true;
|
||||
}
|
||||
// Fail closed, same policy as onContactRemoved()'s Live Share case.
|
||||
if (_node_prefs->loc_share_target_type == 0 && _node_prefs->loc_share_channel_idx == channel_idx) {
|
||||
_node_prefs->loc_share_enabled = 0;
|
||||
changed = true;
|
||||
}
|
||||
uint64_t mask = 1ULL << channel_idx;
|
||||
if (_node_prefs->ch_notif_melody_set & mask) {
|
||||
_node_prefs->ch_notif_melody_set &= ~mask;
|
||||
_node_prefs->ch_notif_melody_2 &= ~mask;
|
||||
changed = true;
|
||||
}
|
||||
if (_node_prefs->ch_notif_override & mask) {
|
||||
_node_prefs->ch_notif_override &= ~mask;
|
||||
_node_prefs->ch_notif_muted &= ~mask;
|
||||
changed = true;
|
||||
}
|
||||
if (_node_prefs->ch_fav_bitmask & mask) {
|
||||
_node_prefs->ch_fav_bitmask &= ~mask;
|
||||
changed = true;
|
||||
}
|
||||
if (channel_idx < NodePrefs::MAX_SCOPED_CHANNELS && _node_prefs->ch_scope_idx[channel_idx]) {
|
||||
_node_prefs->ch_scope_idx[channel_idx] = 0; // back to "*", same as a never-configured channel
|
||||
changed = true;
|
||||
}
|
||||
int fav_slot = findFavouriteChannelSlot(channel_idx);
|
||||
if (fav_slot >= 0) { clearFavouriteSlot(fav_slot); changed = true; }
|
||||
|
||||
if (changed) the_mesh.savePrefs();
|
||||
}
|
||||
|
||||
// Homing beeper: while armed with a target and inside the radius, emit a short
|
||||
// tick whose interval shrinks linearly with distance — slow at the edge, rapid
|
||||
// near the centre. Polls distance a few times a second; silent outside the
|
||||
|
||||
Reference in New Issue
Block a user