diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt index 4b4670378..8796d527b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/feeds/FeedContentState.kt @@ -107,9 +107,10 @@ class FeedContentState( private fun updateFeed(notes: ImmutableList) { if (notes.size >= localFilter.limit()) { - val lastNomeTime = notes.lastOrNull { it.event != null }?.createdAt() - if (lastNomeTime != lastNoteCreatedAtWhenFullyLoaded.value) { - lastNoteCreatedAtWhenFullyLoaded.tryEmit(lastNomeTime) + // feeds might not be sorted by created at, so full search + val lastNoteTime = notes.minOfOrNull { it.createdAt() ?: Long.MAX_VALUE } + if (lastNoteTime != lastNoteCreatedAtWhenFullyLoaded.value) { + lastNoteCreatedAtWhenFullyLoaded.tryEmit(lastNoteTime) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt index 59e3e7801..a22766245 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/CardFeedContentState.kt @@ -78,6 +78,9 @@ class CardFeedContentState( val lastNoteCreatedAtWhenFullyLoaded = MutableStateFlow(null) + private var lastAccount: Account? = null + private var lastNotes: Set? = null + fun sendToTop() { if (scrolltoTopPending) return @@ -89,8 +92,14 @@ class CardFeedContentState( scrolltoTopPending = false } - private var lastAccount: Account? = null - private var lastNotes: Set? = null + fun visibleNotes(): List { + val currentState = _feedContent.value + return if (currentState is CardFeedState.Loaded) { + currentState.feed.value.list + } else { + emptyList() + } + } fun lastNoteCreatedAtIfFilled() = lastNoteCreatedAtWhenFullyLoaded.value @@ -305,8 +314,16 @@ class CardFeedContentState( private fun updateFeed(notes: ImmutableList) { if (notes.size >= localFilter.limit()) { - val lastNomeTime = notes.lastOrNull()?.createdAt() - if (lastNomeTime != lastNoteCreatedAtWhenFullyLoaded.value) { + val lastNoteTime = + notes.minOfOrNull { + val createdAt = it.createdAt() + if (createdAt > 0L) { + createdAt + } else { + Long.MAX_VALUE + } + } + if (lastNoteTime != lastNoteCreatedAtWhenFullyLoaded.value) { lastNoteCreatedAtWhenFullyLoaded.tryEmit(notes.lastOrNull()?.createdAt()) } }