diff --git a/CHANGELOG.md b/CHANGELOG.md index 70a78a9c3e8..65d8acbac24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,7 +48,9 @@ ### 🐞 Fixed - Fixed broken date formatting. [#5101](https://github.com/GetStream/stream-chat-android/pull/5101) - Fixed thread separator ui order. [#5098](https://github.com/GetStream/stream-chat-android/pull/5098) - * `MessageListController.showThreadSeparatorInEmptyThread` was added to control the visibility of the thread separator in empty threads. + * `MessageListController.showThreadSeparatorInEmptyThread` was added to control the visibility of the thread separator in empty threads. +- Fixed `MessageList` scrolling behaviour while receiving a new message. [#5112](https://github.com/GetStream/stream-chat-android/pull/5112) + * `NewMessageState.MyOwn` and `NewMessageState.Other` are now data classes. ### ⬆️ Improved diff --git a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/list/Messages.kt b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/list/Messages.kt index b0ac26e4cdb..f5a6f205d70 100644 --- a/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/list/Messages.kt +++ b/stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/list/Messages.kt @@ -283,7 +283,7 @@ internal fun BoxScope.DefaultMessagesHelperContent( if (shouldScrollToBottom) { coroutineScope.launch { - if (newMessageState == MyOwn && firstVisibleItemIndex.value > 5) { + if (newMessageState is MyOwn && firstVisibleItemIndex.value > 5) { lazyListState.scrollToItem(5) } lazyListState.animateScrollToItem(0) diff --git a/stream-chat-android-ui-common/api/stream-chat-android-ui-common.api b/stream-chat-android-ui-common/api/stream-chat-android-ui-common.api index 829d9a544d5..16921f10a9e 100644 --- a/stream-chat-android-ui-common/api/stream-chat-android-ui-common.api +++ b/stream-chat-android-ui-common/api/stream-chat-android-ui-common.api @@ -1008,7 +1008,13 @@ public final class io/getstream/chat/android/ui/common/state/messages/list/Moder public final class io/getstream/chat/android/ui/common/state/messages/list/MyOwn : io/getstream/chat/android/ui/common/state/messages/list/NewMessageState { public static final field $stable I - public static final field INSTANCE Lio/getstream/chat/android/ui/common/state/messages/list/MyOwn; + public fun (Ljava/lang/Long;)V + public final fun component1 ()Ljava/lang/Long; + public final fun copy (Ljava/lang/Long;)Lio/getstream/chat/android/ui/common/state/messages/list/MyOwn; + public static synthetic fun copy$default (Lio/getstream/chat/android/ui/common/state/messages/list/MyOwn;Ljava/lang/Long;ILjava/lang/Object;)Lio/getstream/chat/android/ui/common/state/messages/list/MyOwn; + public fun equals (Ljava/lang/Object;)Z + public final fun getTs ()Ljava/lang/Long; + public fun hashCode ()I public fun toString ()Ljava/lang/String; } @@ -1018,7 +1024,13 @@ public abstract class io/getstream/chat/android/ui/common/state/messages/list/Ne public final class io/getstream/chat/android/ui/common/state/messages/list/Other : io/getstream/chat/android/ui/common/state/messages/list/NewMessageState { public static final field $stable I - public static final field INSTANCE Lio/getstream/chat/android/ui/common/state/messages/list/Other; + public fun (Ljava/lang/Long;)V + public final fun component1 ()Ljava/lang/Long; + public final fun copy (Ljava/lang/Long;)Lio/getstream/chat/android/ui/common/state/messages/list/Other; + public static synthetic fun copy$default (Lio/getstream/chat/android/ui/common/state/messages/list/Other;Ljava/lang/Long;ILjava/lang/Object;)Lio/getstream/chat/android/ui/common/state/messages/list/Other; + public fun equals (Ljava/lang/Object;)Z + public final fun getTs ()Ljava/lang/Long; + public fun hashCode ()I public fun toString ()Ljava/lang/String; } diff --git a/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/MessageListController.kt b/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/MessageListController.kt index aa280fea904..d2d9e87b1c1 100644 --- a/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/MessageListController.kt +++ b/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/MessageListController.kt @@ -835,7 +835,7 @@ public class MessageListController( (lastMessage.isGiphy() || lastLoadedMessage.id != lastMessage.id) -> { getNewMessageStateForMessage(lastMessage) } - else -> null + else -> getNewMessageStateForMessage(lastMessage) } } @@ -846,7 +846,10 @@ public class MessageListController( */ private fun getNewMessageStateForMessage(message: Message): NewMessageState { val currentUser = user.value - return if (message.user.id == currentUser?.id) MyOwn else Other + return when (message.user.id == currentUser?.id) { + true -> MyOwn(ts = message.getCreatedAtOrNull()?.time) + else -> Other(ts = message.createdAt?.time) + } } /** diff --git a/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/state/messages/list/NewMessageState.kt b/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/state/messages/list/NewMessageState.kt index 1a072df16ae..1ca1f9958e8 100644 --- a/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/state/messages/list/NewMessageState.kt +++ b/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/state/messages/list/NewMessageState.kt @@ -24,9 +24,9 @@ public sealed class NewMessageState /** * If the message is our own (we sent it), we scroll to the bottom of the list. */ -public object MyOwn : NewMessageState() { override fun toString(): String = "MyOwn" } +public data class MyOwn(val ts: Long?) : NewMessageState() /** * If the message is someone else's (we didn't send it), we show a "New message" bubble. */ -public object Other : NewMessageState() { override fun toString(): String = "Other" } +public data class Other(val ts: Long?) : NewMessageState()