using combine instead of merge for syncing until the event appears

This commit is contained in:
Adam Brown 2022-03-13 19:01:24 +00:00
parent a8218b7e66
commit 50e12c8c54
2 changed files with 2 additions and 6 deletions

View File

@ -1,6 +1,5 @@
package app.dapk.st.directory
import android.util.Log
import app.dapk.st.matrix.common.CredentialsStore
import app.dapk.st.matrix.common.RoomId
import app.dapk.st.matrix.common.RoomMember
@ -40,7 +39,6 @@ class DirectoryUseCase(
roomStore.observeUnreadCountById(),
syncService.events()
) { userId, overviewState, localEchos, unread, events ->
Log.e("!!!", "got states")
overviewState.mergeWithLocalEchos(localEchos, userId).map { roomOverview ->
RoomFoo(
overview = roomOverview,

View File

@ -10,10 +10,9 @@ import app.dapk.st.matrix.common.RoomId
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
private var previousJob: Job? = null
@ -70,8 +69,7 @@ class PushAndroidService : FirebaseMessagingService() {
private suspend fun waitForEvent(timeout: Long, eventId: EventId): EventId? {
return withTimeoutOrNull(timeout) {
val syncFlow = module.syncService().startSyncing().map { it as EventId }
merge(syncFlow, module.syncService().observeEvent(eventId))
combine(module.syncService().startSyncing(), module.syncService().observeEvent(eventId)) { _, event -> event }
.firstOrNull {
it == eventId
}