diff --git a/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/disk/VaultDiskSourceImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/disk/VaultDiskSourceImpl.kt index cb9bbf8fd..88144ffc8 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/disk/VaultDiskSourceImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/disk/VaultDiskSourceImpl.kt @@ -55,14 +55,15 @@ class VaultDiskSourceImpl( private val forceSendFlow = bufferedMutableSharedFlow>() override suspend fun saveOfflineCipher(userId: String, cipher: Cipher) { + val id = cipher.id ?: "create_${UUID.randomUUID()}" offlineCiphersDao.insertCiphers( ciphers = listOf( OfflineCipherEntity( - id = cipher.id ?: "create_${UUID.randomUUID()}", + id = id, userId = userId, cipherType = json.encodeToString(cipher.type), cipherJson = json.encodeToString( - cipher.toOfflineCipher().toOfflineCipherJson() + cipher.toOfflineCipher().toOfflineCipherJson(id) ), ), ), diff --git a/app/src/main/java/com/x8bit/bitwarden/data/vault/manager/CipherManagerImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/vault/manager/CipherManagerImpl.kt index f07bd4d0f..e18017e9f 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/vault/manager/CipherManagerImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/vault/manager/CipherManagerImpl.kt @@ -109,6 +109,7 @@ class CipherManagerImpl( // TODO: Why are we doing this? cipher = response.cipher.copy(collectionIds = cipher.collectionIds), ) + vaultDiskSource.deleteOfflineCipher(userId = userId, cipherId = c.id) UpdateCipherResult.Success } } diff --git a/app/src/main/java/com/x8bit/bitwarden/data/vault/repository/util/VaultSdkCipherExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/data/vault/repository/util/VaultSdkCipherExtensions.kt index 897abbf55..7e78f1881 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/vault/repository/util/VaultSdkCipherExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/vault/repository/util/VaultSdkCipherExtensions.kt @@ -96,9 +96,9 @@ fun Cipher.toOfflineCipher(): OfflineCipher = mergeConflict = false, ) -fun OfflineCipher.toOfflineCipherJson(): OfflineCipherJson = +fun OfflineCipher.toOfflineCipherJson(id: String): OfflineCipherJson = OfflineCipherJson( - id = id ?: "create_${UUID.randomUUID()}", + id = id, organizationId = organizationId, folderId = folderId, collectionIds = collectionIds.orEmpty(),