Синхронизирована логика read-индикаторов в диалоге с чат-листом
All checks were successful
Android Kernel Build / build (push) Successful in 16h17m58s

This commit is contained in:
2026-03-14 21:17:21 +07:00
parent d78fb184c6
commit a5ec0595ad

View File

@@ -440,9 +440,19 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
private fun markAllOutgoingAsRead() {
_messages.value =
_messages.value.map { msg ->
if (msg.isOutgoing && msg.status != MessageStatus.READ) {
msg.copy(status = MessageStatus.READ)
} else msg
if (!msg.isOutgoing) return@map msg
val nextStatus =
when (msg.status) {
// Read event can promote only already-sent/delivered messages.
MessageStatus.SENT,
MessageStatus.DELIVERED,
MessageStatus.READ -> MessageStatus.READ
MessageStatus.SENDING,
MessageStatus.ERROR -> msg.status
}
if (nextStatus != msg.status) msg.copy(status = nextStatus) else msg
}
updateCacheFromCurrentMessages()
}
@@ -479,7 +489,17 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
private fun updateMessageStatus(messageId: String, status: MessageStatus) {
_messages.value =
_messages.value.map { msg ->
if (msg.id == messageId) msg.copy(status = status) else msg
if (msg.id != messageId) return@map msg
// Keep read status monotonic: late DELIVERED must not downgrade READ.
val mergedStatus =
when (status) {
MessageStatus.DELIVERED ->
if (msg.status == MessageStatus.READ) MessageStatus.READ
else MessageStatus.DELIVERED
else -> status
}
if (mergedStatus != msg.status) msg.copy(status = mergedStatus) else msg
}
// 🔥 Также обновляем кэш!