kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: remove NodeDB `users` StateFlow
rodzic
84cfe4f990
commit
eeb3363a88
|
@ -3,7 +3,6 @@ package com.geeksville.mesh.model
|
|||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import com.geeksville.mesh.MeshProtos
|
||||
import com.geeksville.mesh.MeshUser
|
||||
import com.geeksville.mesh.MyNodeInfo
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
import com.geeksville.mesh.database.dao.NodeInfoDao
|
||||
|
@ -44,9 +43,6 @@ class NodeDB @Inject constructor(
|
|||
val nodeDBbyID: StateFlow<Map<String, NodeInfo>> get() = _nodeDBbyID
|
||||
val nodes get() = nodeDBbyID
|
||||
|
||||
private val _users = MutableStateFlow<Map<String, MeshUser?>>(mapOf())
|
||||
val users: StateFlow<Map<String, MeshUser?>> get() = _users
|
||||
|
||||
init {
|
||||
nodeInfoDao.getMyNodeInfo().onEach { _myNodeInfo.value = it }
|
||||
.launchIn(processLifecycle.coroutineScope)
|
||||
|
@ -60,7 +56,6 @@ class NodeDB @Inject constructor(
|
|||
|
||||
nodeInfoDao.nodeDBbyID().onEach {
|
||||
_nodeDBbyID.value = it
|
||||
_users.value = it.mapValues { node -> node.value.user }
|
||||
}
|
||||
.launchIn(processLifecycle.coroutineScope)
|
||||
}
|
||||
|
|
|
@ -315,11 +315,9 @@ class UIViewModel @Inject constructor(
|
|||
initialValue = emptyList(),
|
||||
)
|
||||
|
||||
fun getMessagesFrom(contactKey: String) = combine(
|
||||
nodeDB.users,
|
||||
packetRepository.getMessagesFrom(contactKey),
|
||||
) { users, packets ->
|
||||
packets.map {
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
fun getMessagesFrom(contactKey: String) = packetRepository.getMessagesFrom(contactKey).mapLatest { list ->
|
||||
list.map {
|
||||
val defaultUser = MeshUser(
|
||||
it.data.from ?: DataPacket.ID_LOCAL,
|
||||
app.getString(R.string.unknown_username),
|
||||
|
@ -329,7 +327,7 @@ class UIViewModel @Inject constructor(
|
|||
Message(
|
||||
uuid = it.uuid,
|
||||
receivedTime = it.received_time,
|
||||
user = users[it.data.from] ?: defaultUser,
|
||||
user = nodeDB.nodes.value[it.data.from]?.user ?: defaultUser,
|
||||
text = it.data.text.orEmpty(),
|
||||
time = it.data.time,
|
||||
read = it.read,
|
||||
|
|
Ładowanie…
Reference in New Issue