Проработан UI звонков и частичная реализация

This commit is contained in:
2026-03-23 18:25:25 +05:00
parent 9778e3b196
commit 419101a4a9
16 changed files with 792 additions and 181 deletions

View File

@@ -477,15 +477,18 @@ class MessageRepository private constructor(private val context: Context) {
scope.launch {
val startTime = System.currentTimeMillis()
try {
// Шифрование
val encryptResult = MessageCrypto.encryptForSending(text.trim(), toPublicKey)
val encryptedContent = encryptResult.ciphertext
val encryptedKey = encryptResult.encryptedKey
// Шифрование (пропускаем для пустого текста — напр. CALL-сообщения)
val hasContent = text.trim().isNotEmpty()
val encryptResult = if (hasContent) MessageCrypto.encryptForSending(text.trim(), toPublicKey) else null
val encryptedContent = encryptResult?.ciphertext ?: ""
val encryptedKey = encryptResult?.encryptedKey ?: ""
val aesChachaKey =
CryptoManager.encryptWithPassword(
String(encryptResult.plainKeyAndNonce, Charsets.ISO_8859_1),
privateKey
)
if (encryptResult != null) {
CryptoManager.encryptWithPassword(
String(encryptResult.plainKeyAndNonce, Charsets.ISO_8859_1),
privateKey
)
} else ""
// 📝 LOG: Шифрование успешно
MessageLogger.logEncryptionSuccess(
@@ -763,15 +766,26 @@ class MessageRepository private constructor(private val context: Context) {
)
}
// Расшифровываем
// Расшифровываем (CALL и attachment-only сообщения могут иметь пустой или
// зашифрованный пустой content — обрабатываем оба случая безопасно)
val isAttachmentOnly = packet.content.isBlank() ||
(packet.attachments.isNotEmpty() && packet.chachaKey.isBlank())
val plainText =
if (isGroupMessage) {
if (isAttachmentOnly) {
""
} else if (isGroupMessage) {
CryptoManager.decryptWithPassword(packet.content, groupKey!!)
?: throw IllegalStateException("Failed to decrypt group payload")
} else if (plainKeyAndNonce != null) {
MessageCrypto.decryptIncomingWithPlainKey(packet.content, plainKeyAndNonce)
} else {
MessageCrypto.decryptIncoming(packet.content, packet.chachaKey, privateKey)
try {
MessageCrypto.decryptIncoming(packet.content, packet.chachaKey, privateKey)
} catch (e: Exception) {
// Fallback: если дешифровка не удалась (напр. CALL с encrypted empty content)
android.util.Log.w("MessageRepository", "Decryption fallback for ${messageId.take(8)}: ${e.message}")
""
}
}
// 📝 LOG: Расшифровка успешна