From a1ec6c2b0d3b839666b3ca2089599f27962d54fa Mon Sep 17 00:00:00 2001 From: PetarVelikov Date: Fri, 22 Nov 2024 16:09:11 +0100 Subject: [PATCH 1/3] [AND-145] Use correct 'BeforeDate' argument for initial loading of pinned messages. --- .../common/feature/pinned/PinnedMessageListController.kt | 7 +++++++ 1 file changed, 7 insertions(+) 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..536b1d9364b 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 @@ -85,6 +85,13 @@ public class PinnedMessageListController( */ public fun load() { scope.launch { + // Ensure the state is updated with the current date(timestamp) for initial loading + _state.value = PinnedMessageListState( + results = emptyList(), + isLoading = true, + canLoadMore = true, + nextDate = Date(), + ) loadPinnedMessages() } } From 9b2d2a6e9943896243c993d9e94629c5386af361 Mon Sep 17 00:00:00 2001 From: PetarVelikov Date: Fri, 22 Nov 2024 16:35:56 +0100 Subject: [PATCH 2/3] [AND-145] Extract common initial state. --- .../pinned/PinnedMessageListController.kt | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) 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 536b1d9364b..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 @@ -86,12 +79,7 @@ public class PinnedMessageListController( public fun load() { scope.launch { // Ensure the state is updated with the current date(timestamp) for initial loading - _state.value = PinnedMessageListState( - results = emptyList(), - isLoading = true, - canLoadMore = true, - nextDate = Date(), - ) + _state.value = initialState() loadPinnedMessages() } } @@ -137,6 +125,7 @@ public class PinnedMessageListController( ) } } + is Result.Failure -> { logger.d { "Loading pinned messages failed: ${result.value.message}" } _state.update { current -> @@ -154,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(), + ) } From edb46d4c92d8c85b011e0036344f0360eefda89a Mon Sep 17 00:00:00 2001 From: PetarVelikov Date: Fri, 22 Nov 2024 16:40:24 +0100 Subject: [PATCH 3/3] [AND-145] Update CHANGELOG.md. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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