android: keep read ack strictly bounded by visible incoming messages
Some checks failed
Android CI / android (push) Failing after 4m58s
Android Release / release (push) Has started running
CI / test (push) Has been cancelled

This commit is contained in:
Codex
2026-03-09 23:32:22 +03:00
parent 5921215718
commit 15e80262e0
2 changed files with 5 additions and 4 deletions

View File

@@ -714,3 +714,8 @@
- Improved cross-device sync (web <-> android): - Improved cross-device sync (web <-> android):
- `message_read` realtime event now parses `user_id` and `last_read_message_id`. - `message_read` realtime event now parses `user_id` and `last_read_message_id`.
- on `message_read`, Android refreshes chat snapshot from backend to keep unread counters aligned across devices. - on `message_read`, Android refreshes chat snapshot from backend to keep unread counters aligned across devices.
### Step 108 - Strict read boundary by visible incoming only
- Removed fallback read-pointer advancement in `ChatViewModel.acknowledgeLatestMessages(...)` that previously moved `lastReadMessageId` by latest loaded message id.
- Read pointer is now advanced only via `onVisibleIncomingMessageId(...)` from visible incoming rows in `ChatScreen`.
- This prevents read acknowledgements from overshooting beyond what user actually saw during refresh/recompose scenarios.

View File

@@ -656,7 +656,6 @@ class ChatViewModel @Inject constructor(
} }
private fun acknowledgeLatestMessages(messages: List<MessageItem>) { private fun acknowledgeLatestMessages(messages: List<MessageItem>) {
val latestVisible = messages.maxByOrNull { it.id } ?: return
val latestIncoming = messages.asReversed().firstOrNull { !it.isOutgoing } val latestIncoming = messages.asReversed().firstOrNull { !it.isOutgoing }
if (latestIncoming != null && lastDeliveredMessageId != latestIncoming.id) { if (latestIncoming != null && lastDeliveredMessageId != latestIncoming.id) {
@@ -665,9 +664,6 @@ class ChatViewModel @Inject constructor(
markMessageDeliveredUseCase(chatId = chatId, messageId = latestIncoming.id) markMessageDeliveredUseCase(chatId = chatId, messageId = latestIncoming.id)
} }
} }
if ((lastReadMessageId ?: 0L) < latestVisible.id) {
lastReadMessageId = latestVisible.id
}
} }
fun canEdit(message: MessageItem): Boolean { fun canEdit(message: MessageItem): Boolean {