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

[AND-145] Fix pinned message list initial loading #5483

Merged
merged 5 commits into from
Nov 26, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

## stream-chat-android-ui-common
### 🐞 Fixed
- Fix wrong timestamp used for the initial loading of pinned messages in `PinnedMessageListController`. [#5483](https://github.com/GetStream/stream-chat-android/pull/5483)

### ⬆️ Improved

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,12 @@ public class PinnedMessageListController(
private companion object {

private const val QUERY_LIMIT = 30

private val INITIAL_STATE = PinnedMessageListState(
results = emptyList(),
isLoading = true,
canLoadMore = true,
nextDate = Date(),
)
}

/**
* Exposes the current pinned messages list state.
*/
private val _state: MutableStateFlow<PinnedMessageListState> = MutableStateFlow(INITIAL_STATE)
private val _state: MutableStateFlow<PinnedMessageListState> = MutableStateFlow(initialState())
public val state: StateFlow<PinnedMessageListState>
get() = _state

Expand All @@ -85,6 +78,8 @@ public class PinnedMessageListController(
*/
public fun load() {
scope.launch {
// Ensure the state is updated with the current date(timestamp) for initial loading
_state.value = initialState()
loadPinnedMessages()
}
}
Expand Down Expand Up @@ -130,6 +125,7 @@ public class PinnedMessageListController(
)
}
}

is Result.Failure -> {
logger.d { "Loading pinned messages failed: ${result.value.message}" }
_state.update { current ->
Expand All @@ -147,11 +143,20 @@ public class PinnedMessageListController(
logger.d { "No more messages to load" }
false
}

currentState.isLoading -> {
logger.d { "Already loading" }
false
}

else -> true
}
}

private fun initialState() = PinnedMessageListState(
results = emptyList(),
isLoading = true,
canLoadMore = true,
nextDate = Date(),
)
}
Loading