diff --git a/app/src/main/java/org/linphone/ui/main/chat/adapter/ConversationEventAdapter.kt b/app/src/main/java/org/linphone/ui/main/chat/adapter/ConversationEventAdapter.kt index dc6d52b04..efa70fbc9 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/adapter/ConversationEventAdapter.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/adapter/ConversationEventAdapter.kt @@ -28,6 +28,7 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import org.linphone.R +import org.linphone.core.tools.Log import org.linphone.databinding.ChatBubbleIncomingBinding import org.linphone.databinding.ChatBubbleOutgoingBinding import org.linphone.databinding.ChatConversationEventBinding @@ -41,6 +42,8 @@ class ConversationEventAdapter : ListAdapter 0) { + val recyclerView = binding.eventsList + + // Scroll to first unread message if any, unless we are already on it + val firstUnreadMessagePosition = adapter.getFirstUnreadMessagePosition() + val currentPosition = (recyclerView.layoutManager as LinearLayoutManager).findFirstCompletelyVisibleItemPosition() + val indexToScrollTo = if (firstUnreadMessagePosition != -1 && firstUnreadMessagePosition != currentPosition) { + firstUnreadMessagePosition + } else { + adapter.itemCount - 1 + } + + Log.i( + "$TAG Scrolling to position $indexToScrollTo, first unread message is at $firstUnreadMessagePosition" + ) + if (smooth) { + recyclerView.smoothScrollToPosition(indexToScrollTo) + } else { + recyclerView.scrollToPosition(indexToScrollTo) + } + + if (firstUnreadMessagePosition == 0) { + // Return true only if all unread messages don't fit in the recyclerview height + return recyclerView.computeVerticalScrollRange() > recyclerView.height + } + } + return false + } + private fun showChatMessageLongPressMenu(chatMessageModel: MessageModel) { Compatibility.setBlurRenderEffect(binding.root) diff --git a/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt b/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt index eb1f7fc9f..d5b6ca855 100644 --- a/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt +++ b/app/src/main/java/org/linphone/ui/main/chat/model/MessageModel.kt @@ -82,6 +82,8 @@ class MessageModel @WorkerThread constructor( val id = chatMessage.messageId + val isRead = chatMessage.isRead + val isOutgoing = chatMessage.isOutgoing val isInError = chatMessage.state == ChatMessage.State.NotDelivered