Фикс: статус доставки фото в группах — БД больше не откатывает DELIVERED на WAITING
Some checks failed
Android Kernel Build / build (push) Has been cancelled

updateMessageStatusInDb и updateMessageStatusAndAttachmentsInDb теперь проверяют
текущий delivered в БД и никогда не понижают (DELIVERED→WAITING race condition).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 00:54:06 +05:00
parent 73d3b2baf6
commit d94b3ec37a
2 changed files with 11 additions and 1 deletions

View File

@@ -440,6 +440,10 @@ interface MessageDao {
)
suspend fun messageExists(account: String, messageId: String): Boolean
/** Найти сообщение по ID */
@Query("SELECT * FROM messages WHERE account = :account AND message_id = :messageId LIMIT 1")
suspend fun findMessageById(account: String, messageId: String): MessageEntity?
/**
* Отметить все исходящие сообщения к собеседнику как прочитанные Используется когда приходит
* PacketRead от собеседника.

View File

@@ -724,6 +724,9 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
private suspend fun updateMessageStatusInDb(messageId: String, delivered: Int) {
val account = myPublicKey ?: return
try {
// Never downgrade delivery status
val existing = messageDao.findMessageById(account, messageId)
if (existing != null && existing.delivered > delivered) return
messageDao.updateDeliveryStatus(account, messageId, delivered)
} catch (e: Exception) {}
}
@@ -736,10 +739,13 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
) {
val account = myPublicKey ?: return
try {
// Never downgrade delivery status (e.g. DELIVERED→WAITING race)
val existing = messageDao.findMessageById(account, messageId)
val safeDelivered = if (existing != null && existing.delivered > delivered) existing.delivered else delivered
messageDao.updateDeliveryStatusAndAttachments(
account,
messageId,
delivered,
safeDelivered,
attachmentsJson
)
} catch (e: Exception) {}