From 0327928bb1f2e262d602e92fde66f2125bc83781 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 1 Jul 2022 17:10:37 +0200 Subject: [PATCH] Fixed chat room not marked as read when going in it if number of messages is not enough to make the list scrollable --- .../chat/fragments/DetailChatRoomFragment.kt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt b/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt index 117943efb..6b16a4f3b 100644 --- a/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/chat/fragments/DetailChatRoomFragment.kt @@ -1029,9 +1029,12 @@ class DetailChatRoomFragment : MasterFragment 0) { - // Scroll to first unread message if any + val recyclerView = binding.chatMessagesList + + // Scroll to first unread message if any, unless we are already on it val firstUnreadMessagePosition = adapter.getFirstUnreadMessagePosition() - val indexToScrollTo = if (firstUnreadMessagePosition != -1) { + val currentPosition = (recyclerView.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition() + val indexToScrollTo = if (firstUnreadMessagePosition != -1 && firstUnreadMessagePosition != currentPosition) { firstUnreadMessagePosition } else { adapter.itemCount - 1 @@ -1039,11 +1042,15 @@ class DetailChatRoomFragment : MasterFragment recyclerView.height } - return firstUnreadMessagePosition == 0 } return false }