diff --git a/app/src/main/java/com/geeksville/mesh/model/NodeDB.kt b/app/src/main/java/com/geeksville/mesh/database/NodeRepository.kt
similarity index 73%
rename from app/src/main/java/com/geeksville/mesh/model/NodeDB.kt
rename to app/src/main/java/com/geeksville/mesh/database/NodeRepository.kt
index 8b5d0a602..7da648fe2 100644
--- a/app/src/main/java/com/geeksville/mesh/model/NodeDB.kt
+++ b/app/src/main/java/com/geeksville/mesh/database/NodeRepository.kt
@@ -15,32 +15,38 @@
* along with this program. If not, see .
*/
-package com.geeksville.mesh.model
+package com.geeksville.mesh.database
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.coroutineScope
+import com.geeksville.mesh.CoroutineDispatchers
import com.geeksville.mesh.DataPacket
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.database.dao.NodeInfoDao
import com.geeksville.mesh.database.entity.MyNodeEntity
import com.geeksville.mesh.database.entity.NodeEntity
-import kotlinx.coroutines.Dispatchers
+import com.geeksville.mesh.model.NodeSortOption
import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
-import kotlinx.coroutines.flow.launchIn
+import kotlinx.coroutines.flow.conflate
+import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onEach
+import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.withContext
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
-class NodeDB @Inject constructor(
+class NodeRepository @Inject constructor(
processLifecycle: Lifecycle,
private val nodeInfoDao: NodeInfoDao,
+ private val dispatchers: CoroutineDispatchers,
) {
// hardware info about our local device (can be null)
- private val _myNodeInfo = MutableStateFlow(null)
- val myNodeInfo: StateFlow get() = _myNodeInfo
+ val myNodeInfo: StateFlow = nodeInfoDao.getMyNodeInfo()
+ .flowOn(dispatchers.io)
+ .stateIn(processLifecycle.coroutineScope, SharingStarted.Eagerly, null)
// our node info
private val _ourNodeInfo = MutableStateFlow(null)
@@ -51,8 +57,15 @@ class NodeDB @Inject constructor(
val myId: StateFlow get() = _myId
// A map from nodeNum to NodeEntity
- private val _nodeDBbyNum = MutableStateFlow