timeline : makes sure to emit empty list if initial reset has no item.

This commit is contained in:
ganfra 2024-09-25 15:39:20 +02:00
parent c161c8f3b6
commit ade97f6133

View file

@ -80,11 +80,16 @@ internal class TimelineItemsSubscriber(
} }
private suspend fun postItems(items: List<TimelineItem>) = coroutineScope { private suspend fun postItems(items: List<TimelineItem>) = coroutineScope {
if (items.isEmpty()) {
// Makes sure to post empty list if there is no item, so you can handle empty state.
timelineDiffProcessor.postItems(emptyList())
} else {
// Split the initial items in multiple list as there is no pagination in the cached data, so we can post timelineItems asap. // Split the initial items in multiple list as there is no pagination in the cached data, so we can post timelineItems asap.
items.chunked(INITIAL_MAX_SIZE).reversed().forEach { items.chunked(INITIAL_MAX_SIZE).reversed().forEach {
ensureActive() ensureActive()
timelineDiffProcessor.postItems(it) timelineDiffProcessor.postItems(it)
} }
}
isTimelineInitialized.value = true isTimelineInitialized.value = true
initLatch.complete(Unit) initLatch.complete(Unit)
} }