kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: unify service node DB into a single source
rodzic
eeb3363a88
commit
3a6511b7f9
|
@ -334,10 +334,6 @@ class MeshService : Service(), Logging {
|
||||||
|
|
||||||
// put our node array into our two different map representations
|
// put our node array into our two different map representations
|
||||||
nodeDBbyNodeNum.putAll(nodes.map { it.num to it })
|
nodeDBbyNodeNum.putAll(nodes.map { it.num to it })
|
||||||
nodeDBbyID.putAll(nodes.mapNotNull {
|
|
||||||
// ignore records that don't have a valid user
|
|
||||||
it.user?.let { user -> user.id to it }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadSettings() {
|
private fun loadSettings() {
|
||||||
|
@ -362,7 +358,6 @@ class MeshService : Service(), Logging {
|
||||||
debug("Discarding NodeDB")
|
debug("Discarding NodeDB")
|
||||||
myNodeInfo = null
|
myNodeInfo = null
|
||||||
nodeDBbyNodeNum.clear()
|
nodeDBbyNodeNum.clear()
|
||||||
nodeDBbyID.clear()
|
|
||||||
haveNodeDB = false
|
haveNodeDB = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,11 +378,9 @@ class MeshService : Service(), Logging {
|
||||||
// The database of active nodes, index is the node number
|
// The database of active nodes, index is the node number
|
||||||
private val nodeDBbyNodeNum = ConcurrentHashMap<Int, NodeInfo>()
|
private val nodeDBbyNodeNum = ConcurrentHashMap<Int, NodeInfo>()
|
||||||
|
|
||||||
/// The database of active nodes, index is the node user ID string
|
// The database of active nodes, index is the node user ID string
|
||||||
/// NOTE: some NodeInfos might be in only nodeDBbyNodeNum (because we don't yet know
|
// NOTE: some NodeInfos might be in only nodeDBbyNodeNum (because we don't yet know an ID).
|
||||||
/// an ID). But if a NodeInfo is in both maps, it must be one instance shared by
|
private val nodeDBbyID get() = nodeDBbyNodeNum.mapKeys { it.value.user?.id }
|
||||||
/// both datastructures.
|
|
||||||
private val nodeDBbyID = mutableMapOf<String, NodeInfo>()
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// END OF MODEL
|
/// END OF MODEL
|
||||||
|
@ -470,7 +463,6 @@ class MeshService : Service(), Logging {
|
||||||
// This might have been the first time we know an ID for this node, so also update the by ID map
|
// This might have been the first time we know an ID for this node, so also update the by ID map
|
||||||
val userId = info.user?.id.orEmpty()
|
val userId = info.user?.id.orEmpty()
|
||||||
if (userId.isNotEmpty()) {
|
if (userId.isNotEmpty()) {
|
||||||
nodeDBbyID[userId] = info
|
|
||||||
if (haveNodeDB) serviceScope.handledLaunch {
|
if (haveNodeDB) serviceScope.handledLaunch {
|
||||||
radioConfigRepository.upsert(info)
|
radioConfigRepository.upsert(info)
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue