RoomList: try syncing when network is back and inError state

This commit is contained in:
ganfra 2023-06-23 17:07:27 +02:00
parent 1185dbd276
commit bb4f61fe12
6 changed files with 45 additions and 17 deletions

View file

@ -30,7 +30,7 @@ interface SyncService {
fun stopSync()
/**
*
* Flow of [SyncState]. Will be updated as soon as the current [SyncState] changes.
*/
fun syncState(): StateFlow<SyncState>
val syncState: StateFlow<SyncState>
}

View file

@ -114,7 +114,7 @@ class RustMatrixClient constructor(
init {
client.setDelegate(clientDelegate)
syncService.syncState()
syncService.syncState
.onEach { syncState ->
if (syncState == SyncState.Syncing) {
onSlidingSyncUpdate()

View file

@ -22,6 +22,7 @@ import io.element.android.libraries.matrix.impl.room.roomListStateFlow
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
@ -46,13 +47,10 @@ class RustSyncService(
}
}
override fun syncState(): StateFlow<SyncState> {
return roomListService
override val syncState: StateFlow<SyncState> =
roomListService
.roomListStateFlow()
.map(RoomListState::toSyncState)
.onEach { syncState ->
Timber.d("OnSyncState updated = $syncState")
}
.stateIn(sessionCoroutineScope, SharingStarted.Eagerly, SyncState.Idle)
}
.distinctUntilChanged()
.stateIn(sessionCoroutineScope, SharingStarted.WhileSubscribed(), SyncState.Idle)
}

View file

@ -23,21 +23,19 @@ import kotlinx.coroutines.flow.StateFlow
class FakeSyncService : SyncService {
private val syncState = MutableStateFlow(SyncState.Idle)
private val syncStateFlow = MutableStateFlow(SyncState.Idle)
fun simulateError() {
syncState.value = SyncState.InError
syncStateFlow.value = SyncState.InError
}
override fun startSync() {
syncState.value = SyncState.Syncing
syncStateFlow.value = SyncState.Syncing
}
override fun stopSync() {
syncState.value = SyncState.Terminated
syncStateFlow.value = SyncState.Terminated
}
override fun syncState(): StateFlow<SyncState> {
return syncState
}
override val syncState: StateFlow<SyncState> = syncStateFlow
}