Create Viewmodel for Follow sets. Refactor User.followSets to be a collection of Notes. Adjust FollowSetFeedFilter.

This commit is contained in:
KotlinGeekDev
2024-10-27 20:19:23 +01:00
parent caad5066ff
commit 7dec46f3fd
4 changed files with 19 additions and 7 deletions
@@ -108,6 +108,7 @@ import com.vitorpamplona.quartz.events.ZapSplitSetup
import com.vitorpamplona.quartz.signers.NostrSigner import com.vitorpamplona.quartz.signers.NostrSigner
import com.vitorpamplona.quartz.signers.NostrSignerInternal import com.vitorpamplona.quartz.signers.NostrSignerInternal
import com.vitorpamplona.quartz.utils.DualCase import com.vitorpamplona.quartz.utils.DualCase
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -2902,9 +2903,8 @@ class Account(
val sets = val sets =
getFollowSetNotes() getFollowSetNotes()
.fastFilter { !it.dTag().isNullOrBlank() } .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 fun followSetNotesFlow() = userProfile().flow().followSets.stateFlow
@@ -42,10 +42,11 @@ import com.vitorpamplona.quartz.events.ChatroomKey
import com.vitorpamplona.quartz.events.ContactListEvent import com.vitorpamplona.quartz.events.ContactListEvent
import com.vitorpamplona.quartz.events.LnZapEvent import com.vitorpamplona.quartz.events.LnZapEvent
import com.vitorpamplona.quartz.events.MetadataEvent import com.vitorpamplona.quartz.events.MetadataEvent
import com.vitorpamplona.quartz.events.PeopleListEvent
import com.vitorpamplona.quartz.events.ReportEvent import com.vitorpamplona.quartz.events.ReportEvent
import com.vitorpamplona.quartz.events.UserMetadata import com.vitorpamplona.quartz.events.UserMetadata
import com.vitorpamplona.quartz.events.toImmutableListOfLists import com.vitorpamplona.quartz.events.toImmutableListOfLists
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.persistentSetOf import kotlinx.collections.immutable.persistentSetOf
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
@@ -61,7 +62,7 @@ class User(
var latestMetadataRelay: String? = null var latestMetadataRelay: String? = null
var latestContactList: ContactListEvent? = null var latestContactList: ContactListEvent? = null
var latestBookmarkList: BookmarkListEvent? = null var latestBookmarkList: BookmarkListEvent? = null
var followSets: Map<String, PeopleListEvent> = emptyMap() var followSets: ImmutableList<AddressableNote> = persistentListOf()
var reports = mapOf<User, Set<Note>>() var reports = mapOf<User, Set<Note>>()
private set private set
@@ -21,11 +21,12 @@
package com.vitorpamplona.amethyst.ui.dal package com.vitorpamplona.amethyst.ui.dal
import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.quartz.events.PeopleListEvent import com.vitorpamplona.quartz.events.PeopleListEvent
class FollowSetFeedFilter( class FollowSetFeedFilter(
val account: Account, val account: Account,
) : FeedFilter<PeopleListEvent.FollowSet>() { ) : FeedFilter<Note>() {
override fun feedKey(): String = account.userProfile().pubkeyHex override fun feedKey(): String = account.userProfile().pubkeyHex
private fun mapEventToSet(event: PeopleListEvent): PeopleListEvent.FollowSet { private fun mapEventToSet(event: PeopleListEvent): PeopleListEvent.FollowSet {
@@ -54,11 +55,10 @@ class FollowSetFeedFilter(
} }
} }
override fun feed(): List<PeopleListEvent.FollowSet> = override fun feed(): List<Note> =
account account
.followSetNotesFlow() .followSetNotesFlow()
.value .value
.user .user
.followSets .followSets
.map { setEntry -> mapEventToSet(setEntry.value) }
} }
@@ -38,6 +38,7 @@ import com.vitorpamplona.amethyst.ui.dal.ChatroomFeedFilter
import com.vitorpamplona.amethyst.ui.dal.CommunityFeedFilter import com.vitorpamplona.amethyst.ui.dal.CommunityFeedFilter
import com.vitorpamplona.amethyst.ui.dal.DraftEventsFeedFilter import com.vitorpamplona.amethyst.ui.dal.DraftEventsFeedFilter
import com.vitorpamplona.amethyst.ui.dal.FeedFilter 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.GeoHashFeedFilter
import com.vitorpamplona.amethyst.ui.dal.HashtagFeedFilter import com.vitorpamplona.amethyst.ui.dal.HashtagFeedFilter
import com.vitorpamplona.amethyst.ui.dal.NIP90ContentDiscoveryResponseFilter 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 <NostrUserFollowSetFeedViewModel : ViewModel> create(modelClass: Class<NostrUserFollowSetFeedViewModel>): NostrUserFollowSetFeedViewModel = NostrUserFollowSetFeedViewModel(account) as NostrUserFollowSetFeedViewModel
}
}
@Stable @Stable
class NostrNIP90ContentDiscoveryFeedViewModel( class NostrNIP90ContentDiscoveryFeedViewModel(
val account: Account, val account: Account,