feat: Add support for retrieving and displaying attachment types in chat messages

This commit is contained in:
k1ngsterr1
2026-01-25 17:11:43 +05:00
parent b385379850
commit 5c485a3ef1
3 changed files with 69 additions and 5 deletions

View File

@@ -359,6 +359,19 @@ interface MessageDao {
ORDER BY timestamp DESC, id DESC LIMIT 1
""")
suspend fun getLastMessageStatus(account: String, opponent: String): LastMessageStatus?
/**
* 📎 Получить attachments последнего сообщения для диалога
* Возвращает null если сообщений нет или нет attachments
*/
@Query("""
SELECT attachments FROM messages
WHERE account = :account
AND ((from_public_key = :opponent AND to_public_key = :account)
OR (from_public_key = :account AND to_public_key = :opponent))
ORDER BY timestamp DESC, id DESC LIMIT 1
""")
suspend fun getLastMessageAttachments(account: String, opponent: String): String?
}
/**

View File

@@ -1895,10 +1895,18 @@ fun DialogItemContent(
if (isTyping) {
TypingIndicatorSmall()
} else {
// <20> Определяем что показывать - attachment или текст
val displayText = when {
dialog.lastMessageAttachmentType == "Photo" -> "Photo"
dialog.lastMessageAttachmentType == "File" -> "File"
dialog.lastMessage.isEmpty() -> "No messages"
else -> dialog.lastMessage
}
// 🔥 Используем AppleEmojiText для отображения эмодзи
// Если есть непрочитанные - текст темнее
AppleEmojiText(
text = dialog.lastMessage.ifEmpty { "No messages" },
text = displayText,
fontSize = 14.sp,
color =
if (dialog.unreadCount > 0)

View File

@@ -33,7 +33,8 @@ data class DialogUiModel(
val isSavedMessages: Boolean = false, // 📁 Флаг для Saved Messages (account == opponentKey)
val lastMessageFromMe: Int = 0, // Последнее сообщение от меня (0/1)
val lastMessageDelivered: Int = 0, // Статус доставки (0=WAITING, 1=DELIVERED, 2=ERROR)
val lastMessageRead: Int = 0 // Прочитано (0/1)
val lastMessageRead: Int = 0, // Прочитано (0/1)
val lastMessageAttachmentType: String? = null // 📎 Тип attachment: "Photo", "File", или null
)
/**
@@ -147,8 +148,28 @@ class ChatsListViewModel(application: Application) : AndroidViewModel(applicatio
val actualDelivered = if (actualFromMe == 1) (lastMsgStatus?.delivered ?: 0) else 0
val actualRead = if (actualFromMe == 1) (lastMsgStatus?.read ?: 0) else 0
// <20> Определяем тип attachment последнего сообщения
val attachmentType = try {
val attachmentsJson = messageDao.getLastMessageAttachments(publicKey, dialog.opponentKey)
if (!attachmentsJson.isNullOrEmpty() && attachmentsJson != "[]") {
val attachments = org.json.JSONArray(attachmentsJson)
if (attachments.length() > 0) {
val firstAttachment = attachments.getJSONObject(0)
val type = firstAttachment.optInt("type", -1)
when (type) {
2 -> "Photo" // AttachmentType.IMAGE
3 -> "File" // AttachmentType.FILE
else -> null
}
} else null
} else null
} catch (e: Exception) {
android.util.Log.e("ChatsListVM", "Failed to parse attachments", e)
null
}
// 🔥 Лог для отладки - показываем и старые и новые значения
android.util.Log.d("ChatsListVM", "📊 Dialog ${dialog.opponentKey.take(16)}... | OLD: fromMe=${dialog.lastMessageFromMe}, del=${dialog.lastMessageDelivered}, read=${dialog.lastMessageRead} | NEW: fromMe=$actualFromMe, del=$actualDelivered, read=$actualRead")
android.util.Log.d("ChatsListVM", "📊 Dialog ${dialog.opponentKey.take(16)}... | OLD: fromMe=${dialog.lastMessageFromMe}, del=${dialog.lastMessageDelivered}, read=${dialog.lastMessageRead} | NEW: fromMe=$actualFromMe, del=$actualDelivered, read=$actualRead | attachment=$attachmentType")
DialogUiModel(
id = dialog.id,
@@ -165,7 +186,8 @@ class ChatsListViewModel(application: Application) : AndroidViewModel(applicatio
isSavedMessages = isSavedMessages, // 📁 Saved Messages
lastMessageFromMe = actualFromMe, // 🔥 Используем актуальные данные из messages
lastMessageDelivered = actualDelivered, // 🔥 Используем актуальные данные из messages
lastMessageRead = actualRead // 🔥 Используем актуальные данные из messages
lastMessageRead = actualRead, // 🔥 Используем актуальные данные из messages
lastMessageAttachmentType = attachmentType // 📎 Тип attachment
)
}
}
@@ -209,6 +231,26 @@ class ChatsListViewModel(application: Application) : AndroidViewModel(applicatio
dialog.lastMessage
}
// 📎 Определяем тип attachment последнего сообщения
val attachmentType = try {
val attachmentsJson = messageDao.getLastMessageAttachments(publicKey, dialog.opponentKey)
if (!attachmentsJson.isNullOrEmpty() && attachmentsJson != "[]") {
val attachments = org.json.JSONArray(attachmentsJson)
if (attachments.length() > 0) {
val firstAttachment = attachments.getJSONObject(0)
val type = firstAttachment.optInt("type", -1)
when (type) {
2 -> "Photo" // AttachmentType.IMAGE
3 -> "File" // AttachmentType.FILE
else -> null
}
} else null
} else null
} catch (e: Exception) {
android.util.Log.e("ChatsListVM", "Failed to parse attachments in request", e)
null
}
DialogUiModel(
id = dialog.id,
account = dialog.account,
@@ -224,7 +266,8 @@ class ChatsListViewModel(application: Application) : AndroidViewModel(applicatio
isSavedMessages = (dialog.account == dialog.opponentKey), // 📁 Saved Messages
lastMessageFromMe = dialog.lastMessageFromMe,
lastMessageDelivered = dialog.lastMessageDelivered,
lastMessageRead = dialog.lastMessageRead
lastMessageRead = dialog.lastMessageRead,
lastMessageAttachmentType = attachmentType // 📎 Тип attachment
)
}
}