Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voice Broadcast - Handle event deletion when listening or recording #7629

Merged
merged 12 commits into from
Nov 29, 2022
Prev Previous commit
Next Next commit
improve flow stream
  • Loading branch information
Florian Renaud committed Nov 28, 2022
commit aa53105f1713b237b06c059329175cc400784d5e
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,17 +75,15 @@ class GetMostRecentVoiceBroadcastStateEventUseCase @Inject constructor(
// otherwise, observe most recent event changes
getMostRecentRelatedEventFlow(room, voiceBroadcast)
Copy link
Contributor

@mnaturel mnaturel Nov 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you thought about this way of writing this logic?

getMostRecentRelatedEventFlow(room, voiceBroadcast)
                                .transformWhile { mostRecentEvent ->
                                    val hasValue = mostRecentEvent.hasValue()
                                    if(hasValue) {
                                        // keep the most recent event
                                        emit(mostRecentEvent)
                                    } else {
                                        // no most recent event, fallback to started event
                                        emit(startedEvent)
                                    }
                                    hasValue
                                }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely prefer this format, updated aa53105

.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
}
}
}
Expand Down