mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 18:58:59 +03:00
Decode vault database json on default dispatcher (#1043)
This commit is contained in:
parent
018e18c457
commit
8eafb8e180
3 changed files with 19 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.x8bit.bitwarden.data.vault.datasource.disk
|
||||
|
||||
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.data.vault.datasource.disk.dao.CiphersDao
|
||||
import com.x8bit.bitwarden.data.vault.datasource.disk.dao.CollectionsDao
|
||||
|
@ -20,13 +21,14 @@ import kotlinx.coroutines.flow.first
|
|||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.merge
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
/**
|
||||
* Default implementation of [VaultDiskSource].
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
@Suppress("TooManyFunctions", "LongParameterList")
|
||||
class VaultDiskSourceImpl(
|
||||
private val ciphersDao: CiphersDao,
|
||||
private val collectionsDao: CollectionsDao,
|
||||
|
@ -34,6 +36,7 @@ class VaultDiskSourceImpl(
|
|||
private val foldersDao: FoldersDao,
|
||||
private val sendsDao: SendsDao,
|
||||
private val json: Json,
|
||||
private val dispatcherManager: DispatcherManager,
|
||||
) : VaultDiskSource {
|
||||
|
||||
private val forceCiphersFlow = bufferedMutableSharedFlow<List<SyncResponseJson.Cipher>>()
|
||||
|
@ -64,7 +67,9 @@ class VaultDiskSourceImpl(
|
|||
.getAllCiphers(userId = userId)
|
||||
.map { entities ->
|
||||
entities.map { entity ->
|
||||
json.decodeFromString<SyncResponseJson.Cipher>(entity.cipherJson)
|
||||
withContext(dispatcherManager.default) {
|
||||
json.decodeFromString<SyncResponseJson.Cipher>(entity.cipherJson)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
@ -112,7 +117,9 @@ class VaultDiskSourceImpl(
|
|||
domainsDao
|
||||
.getDomains(userId)
|
||||
.map { entity ->
|
||||
json.decodeFromString<SyncResponseJson.Domains>(entity.domainsJson)
|
||||
withContext(dispatcherManager.default) {
|
||||
json.decodeFromString<SyncResponseJson.Domains>(entity.domainsJson)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteFolder(userId: String, folderId: String) {
|
||||
|
@ -174,7 +181,9 @@ class VaultDiskSourceImpl(
|
|||
.getAllSends(userId = userId)
|
||||
.map { entities ->
|
||||
entities.map { entity ->
|
||||
json.decodeFromString<SyncResponseJson.Send>(entity.sendJson)
|
||||
withContext(dispatcherManager.default) {
|
||||
json.decodeFromString<SyncResponseJson.Send>(entity.sendJson)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.x8bit.bitwarden.data.vault.datasource.disk.di
|
|||
|
||||
import android.app.Application
|
||||
import androidx.room.Room
|
||||
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.vault.datasource.disk.VaultDiskSource
|
||||
import com.x8bit.bitwarden.data.vault.datasource.disk.VaultDiskSourceImpl
|
||||
import com.x8bit.bitwarden.data.vault.datasource.disk.convertor.ZonedDateTimeTypeConverter
|
||||
|
@ -67,6 +68,7 @@ class VaultDiskModule {
|
|||
foldersDao: FoldersDao,
|
||||
sendsDao: SendsDao,
|
||||
json: Json,
|
||||
dispatcherManager: DispatcherManager,
|
||||
): VaultDiskSource = VaultDiskSourceImpl(
|
||||
ciphersDao = ciphersDao,
|
||||
collectionsDao = collectionsDao,
|
||||
|
@ -74,5 +76,6 @@ class VaultDiskModule {
|
|||
foldersDao = foldersDao,
|
||||
sendsDao = sendsDao,
|
||||
json = json,
|
||||
dispatcherManager = dispatcherManager,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.x8bit.bitwarden.data.vault.datasource.disk
|
||||
|
||||
import app.cash.turbine.test
|
||||
import com.x8bit.bitwarden.data.platform.base.FakeDispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.di.PlatformNetworkModule
|
||||
import com.x8bit.bitwarden.data.util.assertJsonEquals
|
||||
import com.x8bit.bitwarden.data.vault.datasource.disk.dao.FakeCiphersDao
|
||||
|
@ -34,6 +35,7 @@ import java.time.ZonedDateTime
|
|||
class VaultDiskSourceTest {
|
||||
|
||||
private val json = PlatformNetworkModule.providesJson()
|
||||
private val dispatcherManager: FakeDispatcherManager = FakeDispatcherManager()
|
||||
private lateinit var ciphersDao: FakeCiphersDao
|
||||
private lateinit var collectionsDao: FakeCollectionsDao
|
||||
private lateinit var domainsDao: FakeDomainsDao
|
||||
|
@ -56,6 +58,7 @@ class VaultDiskSourceTest {
|
|||
foldersDao = foldersDao,
|
||||
sendsDao = sendsDao,
|
||||
json = json,
|
||||
dispatcherManager = dispatcherManager,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue