Синхронизирована логика read-индикаторов в диалоге с чат-листом
This commit is contained in:
@@ -440,9 +440,19 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
private fun markAllOutgoingAsRead() {
|
private fun markAllOutgoingAsRead() {
|
||||||
_messages.value =
|
_messages.value =
|
||||||
_messages.value.map { msg ->
|
_messages.value.map { msg ->
|
||||||
if (msg.isOutgoing && msg.status != MessageStatus.READ) {
|
if (!msg.isOutgoing) return@map msg
|
||||||
msg.copy(status = MessageStatus.READ)
|
|
||||||
} else 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()
|
updateCacheFromCurrentMessages()
|
||||||
}
|
}
|
||||||
@@ -479,7 +489,17 @@ class ChatViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
private fun updateMessageStatus(messageId: String, status: MessageStatus) {
|
private fun updateMessageStatus(messageId: String, status: MessageStatus) {
|
||||||
_messages.value =
|
_messages.value =
|
||||||
_messages.value.map { msg ->
|
_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
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔥 Также обновляем кэш!
|
// 🔥 Также обновляем кэш!
|
||||||
|
|||||||
Reference in New Issue
Block a user