mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix: internal regression; if hardware model is unset keep long/short names null (#4079)
This commit is contained in:
parent
09961b500f
commit
d5475a0e0a
2 changed files with 23 additions and 2 deletions
|
|
@ -299,6 +299,20 @@ class NodeInfoDaoTest {
|
|||
assertTrue(containsUnsetNode)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUnknownNodesKeepNamesNullAndRemainFiltered() = runBlocking {
|
||||
val updatedUnknownNode = unknownNode.copy(longName = "Should be cleared", shortName = "SHOULD")
|
||||
|
||||
nodeInfoDao.upsert(updatedUnknownNode)
|
||||
|
||||
val storedUnknown = nodeInfoDao.getNodeByNum(updatedUnknownNode.num)!!.node
|
||||
assertEquals(null, storedUnknown.longName)
|
||||
assertEquals(null, storedUnknown.shortName)
|
||||
|
||||
val nodes = getNodes(includeUnknown = false)
|
||||
assertFalse(nodes.any { it.num == updatedUnknownNode.num })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOfflineNodesIncludedByDefault() = runBlocking {
|
||||
val nodes = getNodes()
|
||||
|
|
|
|||
|
|
@ -51,10 +51,13 @@ interface NodeInfoDao {
|
|||
incomingNode.publicKey = incomingNode.user.publicKey
|
||||
|
||||
// Populate denormalized name columns from the User protobuf for search functionality
|
||||
// Only populate if the user is not a placeholder (hwModel != UNSET)
|
||||
// Only populate if the user is not a placeholder (hwModel != UNSET); otherwise keep them null
|
||||
if (incomingNode.user.hwModel != MeshProtos.HardwareModel.UNSET) {
|
||||
incomingNode.longName = incomingNode.user.longName
|
||||
incomingNode.shortName = incomingNode.user.shortName
|
||||
} else {
|
||||
incomingNode.longName = null
|
||||
incomingNode.shortName = null
|
||||
}
|
||||
|
||||
val existingNodeEntity = getNodeByNum(incomingNode.num)?.node
|
||||
|
|
@ -88,11 +91,15 @@ interface NodeInfoDao {
|
|||
val isPublicKeyMatchingOrExistingIsEmpty =
|
||||
existingNode.user.publicKey == incomingNode.publicKey || existingNode.user.publicKey.isEmpty
|
||||
|
||||
val isPlaceholder = incomingNode.user.hwModel == MeshProtos.HardwareModel.UNSET
|
||||
|
||||
return if (isPublicKeyMatchingOrExistingIsEmpty) {
|
||||
// Keys match or existing key was empty: trust the incoming node data completely.
|
||||
// This allows for legitimate updates to user info and other fields.
|
||||
val resolvedNotes = if (incomingNode.notes.isBlank()) existingNode.notes else incomingNode.notes
|
||||
incomingNode.copy(notes = resolvedNotes)
|
||||
val resolvedLongName = if (isPlaceholder) null else incomingNode.longName ?: existingNode.longName
|
||||
val resolvedShortName = if (isPlaceholder) null else incomingNode.shortName ?: existingNode.shortName
|
||||
incomingNode.copy(notes = resolvedNotes, longName = resolvedLongName, shortName = resolvedShortName)
|
||||
} else {
|
||||
existingNode.copy(
|
||||
lastHeard = incomingNode.lastHeard,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue