Skip to content

Commit a5f2c84

Browse files
committed
Fix stale loadMore results contaminating search in AddMembersViewController. Cancel any in-flight loadMore job when a new search starts, preventing results from a previous query from being appended to the new search results.
1 parent cece209 commit a5f2c84

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/channel/info/AddMembersViewController.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class AddMembersViewController(
6666
private val channelMembers = channelState.flatMapLatest { it.members }
6767

6868
private var searchJob: Job? = null
69+
private var loadMoreJob: Job? = null
6970

7071
private val _state = MutableStateFlow(AddMembersViewState())
7172

@@ -120,6 +121,7 @@ public class AddMembersViewController(
120121

121122
private fun searchUsers(query: String) {
122123
searchJob?.cancel()
124+
loadMoreJob?.cancel()
123125
searchJob = scope.launch {
124126
_state.update { it.copy(isLoading = true) }
125127
chatClient.queryUsers(query.trim().toSearchRequest(offset = 0))
@@ -137,7 +139,7 @@ public class AddMembersViewController(
137139

138140
private fun loadMore() {
139141
if (_state.value.isLoading || _state.value.isLoadingMore) return
140-
scope.launch {
142+
loadMoreJob = scope.launch {
141143
val currentResult = _state.value.searchResult
142144
_state.update { it.copy(isLoadingMore = true) }
143145
chatClient.queryUsers(_state.value.query.trim().toSearchRequest(offset = currentResult.size))

0 commit comments

Comments
 (0)