Refactor: Decoupled role/config check and set role defaults appropriately

This commit is contained in:
ford-jones 2025-10-11 13:45:31 +13:00
parent 39be63d7af
commit 0de61c3986
3 changed files with 8 additions and 8 deletions

View File

@ -402,11 +402,6 @@ NodeDB::NodeDB()
config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED;
config.position.gps_enabled = 0;
}
if (config.device.preserve_favourites ||
IS_ONE_OF(config.device.role, meshtastic_Config_DeviceConfig_Role_CLIENT_BASE, meshtastic_Config_DeviceConfig_Role_ROUTER,
meshtastic_Config_DeviceConfig_Role_ROUTER_LATE)) {
saveFavourites = true;
}
#ifdef USERPREFS_FIRMWARE_EDITION
myNodeInfo.firmware_edition = USERPREFS_FIRMWARE_EDITION;
#endif
@ -988,7 +983,7 @@ void NodeDB::resetNodes()
if (!config.position.fixed_position)
clearLocalPosition();
numMeshNodes = 1;
if (saveFavourites) {
if (config.device.preserve_favourites) {
for (size_t i = 0; i < nodeDatabase.nodes.size(); i++) {
meshtastic_NodeInfoLite &node = nodeDatabase.nodes[i];
if (i > 0 && !node.is_favorite) {

View File

@ -144,8 +144,6 @@ class NodeDB
bool keyIsLowEntropy = false;
bool hasWarned = false;
bool saveFavourites = false;
/// don't do mesh based algorithm for node id assignment (initially)
/// instead just store in flash - possibly even in the initial alpha release do this hack
NodeDB();

View File

@ -634,6 +634,13 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c)
requiresReboot = true;
}
}
// Router, Router Late and Client Base roles persist their favourites through NodeDB reset by default.
// In accordance with the ability to preserve hops when relayed via a favorite added in
// https://github.com/meshtastic/firmware/pull/7992
if (IS_ONE_OF(config.device.role, meshtastic_Config_DeviceConfig_Role_CLIENT_BASE,
meshtastic_Config_DeviceConfig_Role_ROUTER, meshtastic_Config_DeviceConfig_Role_ROUTER_LATE)) {
config.device.preserve_favourites = true;
};
#if USERPREFS_EVENT_MODE
// If we're in event mode, nobody is a Router or Router Late
if (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER ||