diff --git a/CHANGELOG.md b/CHANGELOG.md index 372242a51bc..462e384ad91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/pinned/PinnedMessageListController.kt b/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/pinned/PinnedMessageListController.kt index 3de8aa44bee..622b849e57b 100644 --- a/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/pinned/PinnedMessageListController.kt +++ b/stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/pinned/PinnedMessageListController.kt @@ -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 = MutableStateFlow(INITIAL_STATE) + private val _state: MutableStateFlow = MutableStateFlow(initialState()) public val state: StateFlow get() = _state @@ -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() } } @@ -130,6 +125,7 @@ public class PinnedMessageListController( ) } } + is Result.Failure -> { logger.d { "Loading pinned messages failed: ${result.value.message}" } _state.update { current -> @@ -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(), + ) }