feat: Extract replyToMessageId from attachments and implement custom PBKDF2 key derivation
This commit is contained in:
@@ -284,6 +284,9 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
privateKey
|
||||
)
|
||||
|
||||
// Извлекаем replyToMessageId из attachments
|
||||
val replyToMessageId = extractReplyToMessageId(packet.attachments)
|
||||
|
||||
// 🔒 Шифруем plainMessage с использованием приватного ключа
|
||||
val encryptedPlainMessage = CryptoManager.encryptWithPassword(plainText, privateKey)
|
||||
|
||||
@@ -301,6 +304,7 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
messageId = messageId, // 🔥 Используем сгенерированный messageId!
|
||||
plainMessage = encryptedPlainMessage, // 🔒 Зашифрованный текст
|
||||
attachments = attachmentsJson,
|
||||
replyToMessageId = replyToMessageId, // 🔥 Добавляем replyToMessageId из attachments!
|
||||
dialogKey = dialogKey
|
||||
)
|
||||
|
||||
@@ -552,6 +556,32 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
plainMessage
|
||||
}
|
||||
|
||||
// Десериализуем attachments из JSON
|
||||
val attachmentsList = try {
|
||||
if (attachments.isNotEmpty() && attachments != "[]") {
|
||||
val jsonArray = JSONArray(attachments)
|
||||
(0 until jsonArray.length()).mapNotNull { i ->
|
||||
try {
|
||||
val obj = jsonArray.getJSONObject(i)
|
||||
MessageAttachment(
|
||||
id = obj.optString("id", ""),
|
||||
blob = obj.optString("blob", ""),
|
||||
type = AttachmentType.fromInt(obj.optInt("type", 0)),
|
||||
preview = obj.optString("preview", ""),
|
||||
width = obj.optInt("width", 0),
|
||||
height = obj.optInt("height", 0)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
emptyList()
|
||||
}
|
||||
|
||||
return Message(
|
||||
id = id,
|
||||
messageId = messageId,
|
||||
@@ -562,6 +592,7 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
isFromMe = fromMe == 1,
|
||||
isRead = read == 1,
|
||||
deliveryStatus = DeliveryStatus.fromInt(delivered),
|
||||
attachments = attachmentsList, // Десериализованные attachments
|
||||
replyToMessageId = replyToMessageId
|
||||
)
|
||||
}
|
||||
@@ -599,6 +630,39 @@ class MessageRepository private constructor(private val context: Context) {
|
||||
return jsonArray.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Извлечение replyToMessageId из attachments
|
||||
* Ищет MESSAGES (type=1) attachment и парсит message_id
|
||||
*/
|
||||
private fun extractReplyToMessageId(attachments: List<MessageAttachment>): String? {
|
||||
if (attachments.isEmpty()) return null
|
||||
|
||||
for (attachment in attachments) {
|
||||
if (attachment.type == AttachmentType.MESSAGES) {
|
||||
try {
|
||||
// Берем blob или preview
|
||||
val dataJson = attachment.blob.ifEmpty { attachment.preview }
|
||||
if (dataJson.isEmpty() || dataJson.contains(":")) {
|
||||
// Пропускаем зашифрованные старые сообщения
|
||||
continue
|
||||
}
|
||||
|
||||
val messagesArray = JSONArray(dataJson)
|
||||
if (messagesArray.length() > 0) {
|
||||
val replyMessage = messagesArray.getJSONObject(0)
|
||||
val replyMessageId = replyMessage.optString("message_id", "")
|
||||
if (replyMessageId.isNotEmpty()) {
|
||||
return replyMessageId
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Сериализация attachments в JSON с расшифровкой MESSAGES blob
|
||||
* Для MESSAGES типа blob расшифровывается и сохраняется в preview (как в RN)
|
||||
|
||||
Reference in New Issue
Block a user