mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Enable Offline mode of the SyncService, so that the sync starts automatically when the network is back.
Also rely on the sync state to render the "Offline" banner.
This commit is contained in:
+8
@@ -14,3 +14,11 @@ enum class SyncState {
|
||||
Terminated,
|
||||
Offline,
|
||||
}
|
||||
|
||||
fun SyncState.isConnected() = when (this) {
|
||||
SyncState.Idle,
|
||||
SyncState.Running,
|
||||
SyncState.Error,
|
||||
SyncState.Terminated -> true
|
||||
SyncState.Offline -> false
|
||||
}
|
||||
|
||||
+1
@@ -74,6 +74,7 @@ class RustMatrixClientFactory @Inject constructor(
|
||||
|
||||
val syncService = client.syncService()
|
||||
.withUtdHook(UtdTracker(analyticsService))
|
||||
.withOfflineMode()
|
||||
.finish()
|
||||
|
||||
return RustMatrixClient(
|
||||
|
||||
+6
@@ -19,6 +19,7 @@ import io.element.android.libraries.matrix.api.notificationsettings.Notification
|
||||
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
||||
import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectoryService
|
||||
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
||||
import io.element.android.libraries.matrix.api.sync.SyncService
|
||||
import io.element.android.libraries.matrix.api.verification.SessionVerificationService
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
|
||||
@@ -45,6 +46,11 @@ object SessionMatrixModule {
|
||||
return matrixClient.roomListService
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun providesSyncService(matrixClient: MatrixClient): SyncService {
|
||||
return matrixClient.syncService()
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun providesEncryptionService(matrixClient: MatrixClient): EncryptionService {
|
||||
return matrixClient.encryptionService()
|
||||
|
||||
+1
@@ -14,5 +14,6 @@ import org.matrix.rustcomponents.sdk.UnableToDecryptDelegate
|
||||
|
||||
class FakeRustSyncServiceBuilder : SyncServiceBuilder(NoPointer) {
|
||||
override suspend fun withUtdHook(delegate: UnableToDecryptDelegate): SyncServiceBuilder = this
|
||||
override fun withOfflineMode(): SyncServiceBuilder = this
|
||||
override suspend fun finish(): SyncService = FakeRustSyncService()
|
||||
}
|
||||
|
||||
+7
-1
@@ -13,8 +13,10 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
class FakeSyncService(
|
||||
syncStateFlow: MutableStateFlow<SyncState> = MutableStateFlow(SyncState.Idle)
|
||||
initialSyncState: SyncState = SyncState.Idle,
|
||||
) : SyncService {
|
||||
private val syncStateFlow: MutableStateFlow<SyncState> = MutableStateFlow(initialSyncState)
|
||||
|
||||
var startSyncLambda: () -> Result<Unit> = { Result.success(Unit) }
|
||||
override suspend fun startSync(): Result<Unit> {
|
||||
return startSyncLambda()
|
||||
@@ -26,4 +28,8 @@ class FakeSyncService(
|
||||
}
|
||||
|
||||
override val syncState: StateFlow<SyncState> = syncStateFlow
|
||||
|
||||
suspend fun emitSyncState(syncState: SyncState) {
|
||||
syncStateFlow.emit(syncState)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user