Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[i225] fix message list scrolling on a new message #5112

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (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;
}

Expand All @@ -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 <init> (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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ public class MessageListController(
(lastMessage.isGiphy() || lastLoadedMessage.id != lastMessage.id) -> {
getNewMessageStateForMessage(lastMessage)
}
else -> null
else -> getNewMessageStateForMessage(lastMessage)
}
}

Expand All @@ -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)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading