-
Notifications
You must be signed in to change notification settings - Fork 0
Fix chat message pagination bugs #36
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,7 +68,7 @@ internal fun ChatMessageList( | |
| } | ||
| } | ||
| LaunchedEffect(shouldLoadMore.value) { | ||
| if (shouldLoadMore.value) onLoadMore() | ||
| if (shouldLoadMore.value && !isLoadingMore) onLoadMore() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding the |
||
| } | ||
|
|
||
| LazyColumn( | ||
|
|
@@ -84,13 +84,6 @@ internal fun ChatMessageList( | |
| ), | ||
| reverseLayout = true | ||
| ) { | ||
| if (isLoadingMore) { | ||
| item(key = "loading_more") { | ||
| Box(modifier = Modifier.fillMaxWidth().padding(Spacing.Small), contentAlignment = Alignment.Center) { | ||
| CircularProgressIndicator() | ||
| } | ||
| } | ||
| } | ||
| val reversedItems = chatItems.reversed() | ||
| itemsIndexed(reversedItems, key = { index, item -> | ||
| when (item) { | ||
|
|
@@ -163,5 +156,13 @@ internal fun ChatMessageList( | |
| ) | ||
| } | ||
| } | ||
|
|
||
| if (isLoadingMore) { | ||
| item(key = "loading_more") { | ||
| Box(modifier = Modifier.fillMaxWidth().padding(Spacing.Small), contentAlignment = Alignment.Center) { | ||
| CircularProgressIndicator() | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a potential race condition here. If the user switches to a different chat while
loadMoreMessagesis in progress, the error message from the previous chat could be shown in the new chat's UI. You should verify that thechatIdfor which the request was made still matches thecurrentChatIdbefore updating the state.Note: This same check should also be applied to the
onSuccessblock (lines 340-347) to prevent mixing messages from different chats, although those lines are not part of this specific diff hunk.}.onFailure { e -> if (chatId == currentChatId) { _error.value = "Failed to load older messages: ${e.message}" }