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>>()
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)
),
),
),

View file

@ -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
}
}

View file

@ -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(),