From 15e80262e0af50b3efc6437b79373e81a5a02a00 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 9 Mar 2026 23:32:22 +0300 Subject: [PATCH] android: keep read ack strictly bounded by visible incoming messages --- android/CHANGELOG.md | 5 +++++ .../java/ru/daemonlord/messenger/ui/chat/ChatViewModel.kt | 4 ---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/android/CHANGELOG.md b/android/CHANGELOG.md index 6f17f16..f63b290 100644 --- a/android/CHANGELOG.md +++ b/android/CHANGELOG.md @@ -714,3 +714,8 @@ - Improved cross-device sync (web <-> android): - `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. + +### 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. diff --git a/android/app/src/main/java/ru/daemonlord/messenger/ui/chat/ChatViewModel.kt b/android/app/src/main/java/ru/daemonlord/messenger/ui/chat/ChatViewModel.kt index a2ee8ed..7203a92 100644 --- a/android/app/src/main/java/ru/daemonlord/messenger/ui/chat/ChatViewModel.kt +++ b/android/app/src/main/java/ru/daemonlord/messenger/ui/chat/ChatViewModel.kt @@ -656,7 +656,6 @@ class ChatViewModel @Inject constructor( } private fun acknowledgeLatestMessages(messages: List) { - val latestVisible = messages.maxByOrNull { it.id } ?: return val latestIncoming = messages.asReversed().firstOrNull { !it.isOutgoing } if (latestIncoming != null && lastDeliveredMessageId != latestIncoming.id) { @@ -665,9 +664,6 @@ class ChatViewModel @Inject constructor( markMessageDeliveredUseCase(chatId = chatId, messageId = latestIncoming.id) } } - if ((lastReadMessageId ?: 0L) < latestVisible.id) { - lastReadMessageId = latestVisible.id - } } fun canEdit(message: MessageItem): Boolean {