mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-26 17:14:59 +01:00
improve flow stream
This commit is contained in:
parent
4427156f0b
commit
aa53105f17
@ -27,7 +27,6 @@ import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.transformWhile
|
||||
@ -76,17 +75,15 @@ class GetMostRecentVoiceBroadcastStateEventUseCase @Inject constructor(
|
||||
// otherwise, observe most recent event changes
|
||||
getMostRecentRelatedEventFlow(room, voiceBroadcast)
|
||||
.transformWhile { mostRecentEvent ->
|
||||
emit(mostRecentEvent)
|
||||
mostRecentEvent.hasValue()
|
||||
}
|
||||
.map {
|
||||
if (!it.hasValue()) {
|
||||
// no most recent event, fallback to started event
|
||||
startedEvent
|
||||
val hasValue = mostRecentEvent.hasValue()
|
||||
if (hasValue) {
|
||||
// keep the most recent event
|
||||
emit(mostRecentEvent)
|
||||
} else {
|
||||
// otherwise, keep the most recent event
|
||||
it
|
||||
// no most recent event, fallback to started event
|
||||
emit(startedEvent)
|
||||
}
|
||||
hasValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user