feat: Update database version to 10 and implement migration to clear large blob attachments; adjust blob handling for IMAGE/FILE types in MessageRepository and ChatViewModel
This commit is contained in:
@@ -828,7 +828,8 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
for (attachment in attachments) {
|
||||
val jsonObj = JSONObject()
|
||||
|
||||
// Для MESSAGES типа расшифровываем и re-encrypt
|
||||
// ⚠️ НЕ сохраняем blob для IMAGE/FILE - слишком большие (SQLite CursorWindow 2MB limit)
|
||||
// Только MESSAGES (reply) сохраняем - они небольшие
|
||||
if (attachment.type == AttachmentType.MESSAGES && attachment.blob.isNotEmpty()) {
|
||||
try {
|
||||
// 1. Расшифровываем с ChaCha ключом сообщения
|
||||
@@ -842,7 +843,7 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
// 2. Re-encrypt с приватным ключом для хранения (как в Desktop Архиве)
|
||||
val reEncryptedBlob = CryptoManager.encryptWithPassword(decryptedBlob, privateKey)
|
||||
|
||||
// 3. Сохраняем ЗАШИФРОВАННЫЙ blob в БД
|
||||
// 3. Сохраняем ЗАШИФРОВАННЫЙ blob в БД (только для MESSAGES - они небольшие)
|
||||
jsonObj.put("id", attachment.id)
|
||||
jsonObj.put("blob", reEncryptedBlob) // 🔒 Зашифрован приватным ключом!
|
||||
jsonObj.put("type", attachment.type.value)
|
||||
@@ -850,27 +851,27 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
jsonObj.put("width", attachment.width)
|
||||
jsonObj.put("height", attachment.height)
|
||||
} else {
|
||||
// Fallback - сохраняем как есть
|
||||
// Fallback - пустой blob для IMAGE/FILE
|
||||
jsonObj.put("id", attachment.id)
|
||||
jsonObj.put("blob", attachment.blob)
|
||||
jsonObj.put("blob", "")
|
||||
jsonObj.put("type", attachment.type.value)
|
||||
jsonObj.put("preview", attachment.preview)
|
||||
jsonObj.put("width", attachment.width)
|
||||
jsonObj.put("height", attachment.height)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// Fallback - сохраняем как есть
|
||||
// Fallback - пустой blob
|
||||
jsonObj.put("id", attachment.id)
|
||||
jsonObj.put("blob", attachment.blob)
|
||||
jsonObj.put("blob", "")
|
||||
jsonObj.put("type", attachment.type.value)
|
||||
jsonObj.put("preview", attachment.preview)
|
||||
jsonObj.put("width", attachment.width)
|
||||
jsonObj.put("height", attachment.height)
|
||||
}
|
||||
} else {
|
||||
// Для других типов сохраняем как есть
|
||||
// Для IMAGE/FILE - НЕ сохраняем blob (пустой)
|
||||
jsonObj.put("id", attachment.id)
|
||||
jsonObj.put("blob", attachment.blob)
|
||||
jsonObj.put("blob", "") // Пустой blob для IMAGE/FILE
|
||||
jsonObj.put("type", attachment.type.value)
|
||||
jsonObj.put("preview", attachment.preview)
|
||||
jsonObj.put("width", attachment.width)
|
||||
|
||||
Reference in New Issue
Block a user