fix: skip nodeinfo upsert when we recieve defaults from the node (#3796)

This commit is contained in:
Mac DeCourcy
2025-11-24 06:13:31 -08:00
committed by GitHub
parent 5d61e78f37
commit 552097888f

View File

@@ -1719,13 +1719,30 @@ class MeshService : Service() {
// Just replace/add any entry
updateNodeInfo(info.num) {
if (info.hasUser()) {
it.user =
info.user.copy {
if (isLicensed) clearPublicKey()
if (info.viaMqtt) longName = "$longName (MQTT)"
}
it.longName = it.user.longName
it.shortName = it.user.shortName
// Check if this is a default/unknown user from firmware (node was evicted and re-created)
val isDefaultName = info.user.longName.matches(Regex("^Meshtastic [0-9a-fA-F]{4}$"))
val isDefaultHwModel = info.user.hwModel == MeshProtos.HardwareModel.UNSET
val hasExistingUser = it.user.id.isNotEmpty() && it.user.hwModel != MeshProtos.HardwareModel.UNSET
// If firmware sends a default user (evicted node), preserve our existing user data
val shouldPreserveExisting = hasExistingUser && isDefaultName && isDefaultHwModel
if (shouldPreserveExisting) {
// Firmware sent us a placeholder - keep all our existing user data
Timber.d(
"Preserving existing user data for node ${info.num}: " +
"kept='${it.user.longName}' (hwModel=${it.user.hwModel}), " +
"skipped default='${info.user.longName}' (hwModel=UNSET)",
)
} else {
it.user =
info.user.copy {
if (isLicensed) clearPublicKey()
if (info.viaMqtt) longName = "$longName (MQTT)"
}
it.longName = it.user.longName
it.shortName = it.user.shortName
}
}
if (info.hasPosition()) {