sforkowany z mirror/meshtastic-android
refactor: simplify packetResponse using filterNotNull and firstOrNull
rodzic
d1ce014a88
commit
3bbe3fd7f7
|
@ -40,6 +40,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.filterNotNull
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
|
@ -156,10 +157,8 @@ class UIViewModel @Inject constructor(
|
|||
_ourNodeInfo.value = it
|
||||
}.launchIn(viewModelScope)
|
||||
|
||||
combine(_meshLog, requestId) { packet, requestId ->
|
||||
requestId?.run { packet.lastOrNull { it.meshPacket?.decoded?.requestId == requestId } }
|
||||
}.onEach {
|
||||
_packetResponse.value = it
|
||||
combine(meshLog, requestId.filterNotNull()) { packet, id ->
|
||||
_packetResponse.value = packet.firstOrNull { it.meshPacket?.decoded?.requestId == id }
|
||||
}.launchIn(viewModelScope)
|
||||
|
||||
debug("ViewModel created")
|
||||
|
|
Ładowanie…
Reference in New Issue