Fix create id

This commit is contained in:
Hinton 2024-10-24 14:54:23 -07:00
parent e44cfe16d5
commit d7b935031e
No known key found for this signature in database
GPG key ID: 5F7295599C5D965C
3 changed files with 6 additions and 4 deletions

View file

@ -55,14 +55,15 @@ class VaultDiskSourceImpl(
private val forceSendFlow = bufferedMutableSharedFlow<List<SyncResponseJson.Send>>() private val forceSendFlow = bufferedMutableSharedFlow<List<SyncResponseJson.Send>>()
override suspend fun saveOfflineCipher(userId: String, cipher: Cipher) { override suspend fun saveOfflineCipher(userId: String, cipher: Cipher) {
val id = cipher.id ?: "create_${UUID.randomUUID()}"
offlineCiphersDao.insertCiphers( offlineCiphersDao.insertCiphers(
ciphers = listOf( ciphers = listOf(
OfflineCipherEntity( OfflineCipherEntity(
id = cipher.id ?: "create_${UUID.randomUUID()}", id = id,
userId = userId, userId = userId,
cipherType = json.encodeToString(cipher.type), cipherType = json.encodeToString(cipher.type),
cipherJson = json.encodeToString( cipherJson = json.encodeToString(
cipher.toOfflineCipher().toOfflineCipherJson() cipher.toOfflineCipher().toOfflineCipherJson(id)
), ),
), ),
), ),

View file

@ -109,6 +109,7 @@ class CipherManagerImpl(
// TODO: Why are we doing this? // TODO: Why are we doing this?
cipher = response.cipher.copy(collectionIds = cipher.collectionIds), cipher = response.cipher.copy(collectionIds = cipher.collectionIds),
) )
vaultDiskSource.deleteOfflineCipher(userId = userId, cipherId = c.id)
UpdateCipherResult.Success UpdateCipherResult.Success
} }
} }

View file

@ -96,9 +96,9 @@ fun Cipher.toOfflineCipher(): OfflineCipher =
mergeConflict = false, mergeConflict = false,
) )
fun OfflineCipher.toOfflineCipherJson(): OfflineCipherJson = fun OfflineCipher.toOfflineCipherJson(id: String): OfflineCipherJson =
OfflineCipherJson( OfflineCipherJson(
id = id ?: "create_${UUID.randomUUID()}", id = id,
organizationId = organizationId, organizationId = organizationId,
folderId = folderId, folderId = folderId,
collectionIds = collectionIds.orEmpty(), collectionIds = collectionIds.orEmpty(),