Фикс: статус доставки фото в группах — БД больше не откатывает DELIVERED на WAITING
Some checks failed
Android Kernel Build / build (push) Has been cancelled
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:
@@ -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 от собеседника.
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
Reference in New Issue
Block a user