From 7dec46f3fdfe8c9fefae1095680b4610836cea46 Mon Sep 17 00:00:00 2001 From: KotlinGeekDev Date: Sun, 27 Oct 2024 20:19:23 +0100 Subject: [PATCH] Create Viewmodel for Follow sets. Refactor User.followSets to be a collection of Notes. Adjust FollowSetFeedFilter. --- .../java/com/vitorpamplona/amethyst/model/Account.kt | 4 ++-- .../java/com/vitorpamplona/amethyst/model/User.kt | 5 +++-- .../amethyst/ui/dal/FollowSetFeedFilter.kt | 6 +++--- .../vitorpamplona/amethyst/ui/screen/FeedViewModel.kt | 11 +++++++++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index 8ad155b96..63cc4b6a5 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -108,6 +108,7 @@ import com.vitorpamplona.quartz.events.ZapSplitSetup import com.vitorpamplona.quartz.signers.NostrSigner import com.vitorpamplona.quartz.signers.NostrSignerInternal import com.vitorpamplona.quartz.utils.DualCase +import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers @@ -2902,9 +2903,8 @@ class Account( val sets = getFollowSetNotes() .fastFilter { !it.dTag().isNullOrBlank() } - .associate { note -> note.dTag().toString() to note.event as PeopleListEvent } - userProfile().followSets = sets + userProfile().followSets = sets.toImmutableList() } fun followSetNotesFlow() = userProfile().flow().followSets.stateFlow diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/User.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/User.kt index 37611d7a2..fdcf65915 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/User.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/User.kt @@ -42,10 +42,11 @@ import com.vitorpamplona.quartz.events.ChatroomKey import com.vitorpamplona.quartz.events.ContactListEvent import com.vitorpamplona.quartz.events.LnZapEvent import com.vitorpamplona.quartz.events.MetadataEvent -import com.vitorpamplona.quartz.events.PeopleListEvent import com.vitorpamplona.quartz.events.ReportEvent import com.vitorpamplona.quartz.events.UserMetadata import com.vitorpamplona.quartz.events.toImmutableListOfLists +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentSetOf import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow @@ -61,7 +62,7 @@ class User( var latestMetadataRelay: String? = null var latestContactList: ContactListEvent? = null var latestBookmarkList: BookmarkListEvent? = null - var followSets: Map = emptyMap() + var followSets: ImmutableList = persistentListOf() var reports = mapOf>() private set diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt index 188fe6a74..d766d8060 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FollowSetFeedFilter.kt @@ -21,11 +21,12 @@ package com.vitorpamplona.amethyst.ui.dal import com.vitorpamplona.amethyst.model.Account +import com.vitorpamplona.amethyst.model.Note import com.vitorpamplona.quartz.events.PeopleListEvent class FollowSetFeedFilter( val account: Account, -) : FeedFilter() { +) : FeedFilter() { override fun feedKey(): String = account.userProfile().pubkeyHex private fun mapEventToSet(event: PeopleListEvent): PeopleListEvent.FollowSet { @@ -54,11 +55,10 @@ class FollowSetFeedFilter( } } - override fun feed(): List = + override fun feed(): List = account .followSetNotesFlow() .value .user .followSets - .map { setEntry -> mapEventToSet(setEntry.value) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt index b8c5e8eb1..b1e5e5151 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt @@ -38,6 +38,7 @@ import com.vitorpamplona.amethyst.ui.dal.ChatroomFeedFilter import com.vitorpamplona.amethyst.ui.dal.CommunityFeedFilter import com.vitorpamplona.amethyst.ui.dal.DraftEventsFeedFilter import com.vitorpamplona.amethyst.ui.dal.FeedFilter +import com.vitorpamplona.amethyst.ui.dal.FollowSetFeedFilter import com.vitorpamplona.amethyst.ui.dal.GeoHashFeedFilter import com.vitorpamplona.amethyst.ui.dal.HashtagFeedFilter import com.vitorpamplona.amethyst.ui.dal.NIP90ContentDiscoveryResponseFilter @@ -215,6 +216,16 @@ class NostrBookmarkPrivateFeedViewModel( } } +class NostrUserFollowSetFeedViewModel( + val account: Account, +) : FeedViewModel(FollowSetFeedFilter(account)) { + class Factory( + val account: Account, + ) : ViewModelProvider.Factory { + override fun create(modelClass: Class): NostrUserFollowSetFeedViewModel = NostrUserFollowSetFeedViewModel(account) as NostrUserFollowSetFeedViewModel + } +} + @Stable class NostrNIP90ContentDiscoveryFeedViewModel( val account: Account,