From dcad12f8360a6799852ece874dd9c57939a3bad2 Mon Sep 17 00:00:00 2001 From: Believethehype <1097224+believethehype@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:01:16 +0200 Subject: [PATCH] load older notes in feed --- .../service/NostrUserProfileDataSource.kt | 2 +- .../ui/dal/UserProfileGalleryFeedFilter.kt | 14 ++-- .../ui/screen/loggedIn/ProfileGallery.kt | 69 ++++++++----------- 3 files changed, 39 insertions(+), 46 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrUserProfileDataSource.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrUserProfileDataSource.kt index 3f7139549..cdd60db09 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrUserProfileDataSource.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrUserProfileDataSource.kt @@ -84,7 +84,7 @@ object NostrUserProfileDataSource : AmethystNostrDataSource("UserProfileFeed") { WikiNoteEvent.KIND, ), authors = listOf(it.pubkeyHex), - limit = 500, + limit = 200, ), ) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileGalleryFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileGalleryFeedFilter.kt index a4fc5eba2..5b84eeacf 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileGalleryFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/UserProfileGalleryFeedFilter.kt @@ -32,7 +32,7 @@ class UserProfileGalleryFeedFilter( val user: User, val account: Account, ) : AdditiveFeedFilter() { - override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + account.defaultStoriesFollowList.value + override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + "ProfileGallery" override fun showHiddenKey(): Boolean = account.defaultStoriesFollowList.value == PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) || @@ -46,13 +46,17 @@ class UserProfileGalleryFeedFilter( acceptableEvent(it, params, user) } + var sorted = sort(notes) var finalnotes = setOf() - for (item in notes) { - item.associatedNote = (item.event as ProfileGalleryEntryEvent).event()?.let { LocalCache.getOrCreateNote(it) } - finalnotes = finalnotes + item + for (item in sorted) { + val note = (item.event as ProfileGalleryEntryEvent).event()?.let { LocalCache.checkGetOrCreateNote(it) } + if (note != null) { + note.associatedNote = item + finalnotes = finalnotes + note + } } - return sort(finalnotes) + return finalnotes.toList() } override fun applyFilter(collection: Set): Set = innerApplyFilter(collection) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt index 730db72dc..fbf2af6a8 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ProfileGallery.kt @@ -133,45 +133,27 @@ private fun GalleryFeedLoaded( itemsIndexed(state.feed.value, key = { _, item -> item.idHex }) { _, item -> val defaultModifier = remember { Modifier.fillMaxWidth().animateItemPlacement() } - if (item.associatedNote != null) { - if (item.associatedNote!!.event != null) { - if ((item.event as ProfileGalleryEntryEvent).hasUrl() && - (item.event as ProfileGalleryEntryEvent).hasEvent() - ) { - val image = (item.event as ProfileGalleryEntryEvent).url() - - Row(defaultModifier) { - if (image != null) { - GalleryCardCompose( - galleryNote = item, - image = image, - baseNote = item.associatedNote!!, - routeForLastRead = routeForLastRead, - modifier = Modifier, - forceEventKind = forceEventKind, - accountViewModel = accountViewModel, - nav = nav, - ) - } - } - - HorizontalDivider( - thickness = DividerThickness, - ) - } else { - accountViewModel.delete(item) - } - } + Row(defaultModifier) { + GalleryCardCompose( + baseNote = item, + routeForLastRead = routeForLastRead, + modifier = Modifier, + forceEventKind = forceEventKind, + accountViewModel = accountViewModel, + nav = nav, + ) } + + HorizontalDivider( + thickness = DividerThickness, + ) } } } @Composable fun GalleryCardCompose( - galleryNote: Note, baseNote: Note, - image: String, routeForLastRead: String? = null, modifier: Modifier = Modifier, parentBackgroundColor: MutableState? = null, @@ -190,15 +172,22 @@ fun GalleryCardCompose( nav = nav, ) { canPreview -> - GalleryCard( - galleryNote = galleryNote, - baseNote = baseNote, - image = image, - modifier = modifier, - parentBackgroundColor = parentBackgroundColor, - accountViewModel = accountViewModel, - nav = nav, - ) + if (baseNote.associatedNote != null) { + if (baseNote.associatedNote!!.event != null) { + val image = (baseNote.associatedNote!!.event as ProfileGalleryEntryEvent).url() + if (image != null) { + GalleryCard( + galleryNote = baseNote.associatedNote!!, + baseNote = baseNote, + image = image, + modifier = modifier, + parentBackgroundColor = parentBackgroundColor, + accountViewModel = accountViewModel, + nav = nav, + ) + } + } + } } } }