Fix cloud sync

This commit is contained in:
Rafał Kobyłko 2023-10-21 21:53:27 +02:00
parent 97b546007b
commit e64542d90c
2 changed files with 11 additions and 4 deletions

View File

@ -252,10 +252,7 @@ class BackupRepositoryImpl(
try {
val backupContent = json.decodeFromString<BackupContent>(result.fileContent)
remoteBackupStatusPreference.put {
it.copy(
reference = backupContent.reference,
lastSyncMillis = backupContent.updatedAt,
)
it.copy(reference = backupContent.reference)
}
// Decrypt backup

View File

@ -1,10 +1,14 @@
package com.twofasapp.data.services
import com.twofasapp.common.coroutines.Dispatchers
import com.twofasapp.data.services.domain.CloudSyncTrigger
import com.twofasapp.data.services.domain.Group
import com.twofasapp.data.services.local.GroupsLocalSource
import com.twofasapp.data.services.local.ServicesLocalSource
import com.twofasapp.data.services.mapper.asDomain
import com.twofasapp.data.services.remote.CloudSyncWorkDispatcher
import com.twofasapp.prefs.model.RemoteBackupStatusEntity
import com.twofasapp.prefs.usecase.RemoteBackupStatusPreference
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
@ -14,6 +18,8 @@ internal class GroupsRepositoryImpl(
private val dispatchers: Dispatchers,
private val local: GroupsLocalSource,
private val localServices: ServicesLocalSource,
private val cloudSyncWorkDispatcher: CloudSyncWorkDispatcher,
private val remoteBackupStatusPreference: RemoteBackupStatusPreference,
) : GroupsRepository {
override fun observeGroups(): Flow<List<Group>> {
@ -41,6 +47,10 @@ internal class GroupsRepositoryImpl(
local.addGroup(name)
localServices.cleanUpGroups(local.getGroups().ids)
}
if (remoteBackupStatusPreference.get().state == RemoteBackupStatusEntity.State.ACTIVE) {
cloudSyncWorkDispatcher.tryDispatch(CloudSyncTrigger.GroupsChanged)
}
}
override suspend fun addGroup(group: Group) {